flipper-zero-tutorials/gpio/gpio_blink/README.md

44 lines
1.4 KiB
Markdown
Raw Normal View History

2023-06-12 01:37:51 +00:00
# GPIO_BLINK
2023-07-01 13:45:06 +00:00
This is the classic "Hello World" of GPIO, where we blink an LED. You will need an LED (any color is fine) and a resistor (220 ohms - 1 kiliohm should be fine). Connect the long side of the LED into pin A7. Connect the short size of the LED to one side of the resistor (doesn't matter which side). Connect the other side of the resistor to any of the pin GND.
2023-06-12 01:37:51 +00:00
Run the application and the LED should start blinking. Hold the back button to exit.
## How it works
2023-07-01 13:45:06 +00:00
- For list of pins see [/firmware/targets/f7/furi_hal/furi_hal_resources.c](https://github.com/flipperdevices/flipperzero-firmware/blob/dev/firmware/targets/f7/furi_hal/furi_hal_resources.c) in your firmware repo.
2023-06-12 01:37:51 +00:00
- We define a variable for our LED...
```c
const GpioPin* const pin_led = &gpio_ext_pa7;
```
- We initialize the pin for output.
2023-07-01 13:45:06 +00:00
- ``GpioModeOutputPushPull`` means true = 3.3 volts, false = 0 volts.
- ``GpioModeOutputOpenDrain`` means true = floating, false = 0 volts.
2023-06-12 01:37:51 +00:00
```c
furi_hal_gpio_init_simple(pin_led, GpioModeOutputOpenDrain);
```
2023-07-01 13:45:06 +00:00
- We turn the LED on (3.3 volts on the pin).
2023-06-12 01:37:51 +00:00
```c
furi_hal_gpio_write(pin_led, true);
```
2023-07-01 13:45:06 +00:00
- We wait 500 ms.
2023-06-12 01:37:51 +00:00
```c
furi_delay_ms(500);
```
2023-07-01 13:45:06 +00:00
- We turn the LED off (0 volts on the pin).
2023-06-12 01:37:51 +00:00
```c
furi_hal_gpio_write(pin_led, false);
```
2023-07-01 13:45:06 +00:00
- We wait 500 ms.
2023-06-12 01:37:51 +00:00
```c
furi_delay_ms(500);
```
- We loop if the back button is not currently pressed.
```c
while(furi_hal_gpio_read(pin_back))
```