mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-12-24 14:03:55 +01:00
LEDs and basic GPIO example application
Description
The application leds_shell is a basic example, which allows easy, interactive
control of internal board LEDs, and basic GPIO for externally connected simple
devices (for e.g. additional LEDs, relay, motors - via dedicated drivers, etc.).
In particular, this example shows:
- on/off and toggle internal board LEDs.
- initialize GPIO port in output mode.
- set GPIO port state to HIGH or LOW.
Shell command
The following commands are available:
led0,led1...led7: allows switching on/off or toggle internal board LEDs. Number of commands depends on internal LEDs number.init: call before interact with GPIO port to initialize chosen port in output mode, which allows setting it to HIGH or LOW state.set: sets GPIO port state to HIGH.clear: sets GPIO port stet to LOW.help: default RIOT command, which shows available commands.
Example on native
- Build and run
LEDsexample application on thenativetarget, as Linux application:
$ make term
[...]
RIOT native interrupts/signals initialized.
RIOT native board initialized.
RIOT native hardware initialization complete.
main(): This is RIOT! (Version: 2021.07-devel-10893-gb2e97-example-leds_shell)
leds_shell, version 1.0.0
>
Or run it directly without terminal. Go to RIOT/examples/leds_shell and run
commands:
$ make
[...]
$ ./bin/native/leds_shell.elf
RIOT native interrupts/signals initialized.
RIOT native board initialized.
RIOT native hardware initialization complete.
main(): This is RIOT! (Version: 2021.07-devel-10893-gb2e97-example-leds_shell)
leds_shell, version 1.0.0
>
- List the available commands:
> help
help
Command Description
---------------------------------------
init GPIO pin initialization
set Set GPIO pin to HIGH
clear Set GPIO pin to LOW
led0 Switch on/off on-board LED0
led1 Switch on/off on-board LED1
- Enable internal LED0 and LED1 (the
nativetarget has two virtual LEDs):
> led0 on
led0 on
LED_RED_ON
> led1 on
led1 on
LED_GREEN_ON
Example on sample board - stm32f469i-disco
- Build and flash
leds_shellexample application on sample board, for examplestm32f469i-discotarget, which has 4 internal LEDs:
$ make BOARD=stm32f469i-disco flash term
[...]
main(): This is RIOT! (Version: 2021.07-devel-10894-g2ad22b9-example-leds_shell)
leds_shell, version 1.0.0
> help
help
Command Description
---------------------------------------
init GPIO pin initialization
set Set GPIO pin to HIGH
clear Set GPIO pin to LOW
led0 Switch on/off on-board LED0
led1 Switch on/off on-board LED1
led2 Switch on/off on-board LED2
led3 Switch on/off on-board LED3
- Switch on/off internal LEDs using commands
led0,led1,led2orled3.