mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
tests/leds: add test where LEDs are mapped to buttons
This commit is contained in:
parent
615d863c00
commit
8da2e1045e
@ -3,4 +3,7 @@ include ../Makefile.tests_common
|
||||
# Some boards do not initialize LED0 by default
|
||||
CFLAGS=-DPERIPH_INIT_LED0
|
||||
|
||||
# auto-init on board buttons as well
|
||||
USEMODULE += periph_init_buttons
|
||||
|
||||
include $(RIOTBASE)/Makefile.include
|
||||
|
@ -5,6 +5,9 @@ endless loop. Each LED will light up once long, and twice short, where the long
|
||||
interval is roughly 4 times as long as the short interval. The length of the
|
||||
interval is not specified and differs for each platform.
|
||||
|
||||
Afterwards the test will connect each on-board button to an LED (if available),
|
||||
so that that LED state mirrors the button state.
|
||||
|
||||
Background
|
||||
==========
|
||||
Running this test shows if all the direct access macros for all on-board LEDs
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include "clk.h"
|
||||
#include "board.h"
|
||||
#include "periph_conf.h"
|
||||
#include "periph/gpio.h"
|
||||
|
||||
#define DELAY_SHORT (coreclk() / 50)
|
||||
#define DELAY_LONG (DELAY_SHORT * 4)
|
||||
@ -81,10 +82,10 @@ int main(void)
|
||||
}
|
||||
else {
|
||||
printf("Available LEDs: %i\n\n", numof);
|
||||
puts("Will now light up each LED once short and twice long in a loop");
|
||||
puts("Will now light up each LED once short and twice long");
|
||||
}
|
||||
|
||||
while (1) {
|
||||
for (unsigned i = 0; i < 4; ++i) {
|
||||
#ifdef LED0_ON
|
||||
LED0_ON;
|
||||
dumb_delay(DELAY_LONG);
|
||||
@ -199,5 +200,34 @@ int main(void)
|
||||
#endif
|
||||
}
|
||||
|
||||
puts("Mapping each LED to a button (if available)");
|
||||
|
||||
while (1) {
|
||||
#if defined(LED0_PIN) && defined(BTN0_PIN)
|
||||
gpio_write(LED0_PIN, gpio_read(BTN0_PIN));
|
||||
#endif
|
||||
#if defined(LED1_PIN) && defined(BTN1_PIN)
|
||||
gpio_write(LED1_PIN, gpio_read(BTN1_PIN));
|
||||
#endif
|
||||
#if defined(LED2_PIN) && defined(BTN2_PIN)
|
||||
gpio_write(LED2_PIN, gpio_read(BTN2_PIN));
|
||||
#endif
|
||||
#if defined(LED3_PIN) && defined(BTN3_PIN)
|
||||
gpio_write(LED3_PIN, gpio_read(BTN3_PIN));
|
||||
#endif
|
||||
#if defined(LED4_PIN) && defined(BTN4_PIN)
|
||||
gpio_write(LED4_PIN, gpio_read(BTN4_PIN));
|
||||
#endif
|
||||
#if defined(LED5_PIN) && defined(BTN5_PIN)
|
||||
gpio_write(LED5_PIN, gpio_read(BTN5_PIN));
|
||||
#endif
|
||||
#if defined(LED6_PIN) && defined(BTN6_PIN)
|
||||
gpio_write(LED6_PIN, gpio_read(BTN6_PIN));
|
||||
#endif
|
||||
#if defined(LED7_PIN) && defined(BTN7_PIN)
|
||||
gpio_write(LED7_PIN, gpio_read(BTN7_PIN));
|
||||
#endif
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user