add simple led demo
This commit is contained in:
parent
3cb09b472c
commit
a5818ebe07
35
main.c
35
main.c
@ -33,6 +33,7 @@
|
||||
#include "global.h" // board definitions
|
||||
#include "usart.h" // USART utilities
|
||||
#include "usb_cdcacm.h" // USB CDC ACM utilities
|
||||
#include "led_ws2812b.h" // WS2812b LEDs utilities
|
||||
|
||||
/* flag set in interrupts to be processed in main taks */
|
||||
volatile bool button_flag = false; // button has been presse
|
||||
@ -109,22 +110,48 @@ int main(void)
|
||||
nvic_enable_irq(BUTTON_IRQ); // enable interrupt
|
||||
#endif
|
||||
|
||||
printf("welcome to the STM32F1 CuVoodoo example code\n"); // print welcome message
|
||||
ws2812b_setup(); // setup WS2812b LEDs
|
||||
|
||||
printf("welcome to the CuVoodoo LED clock\n"); // print welcome message
|
||||
led_on(); // switch on LED to indicate setup completed
|
||||
|
||||
bool action = false; // if an action has been performed don't go to sleep
|
||||
button_flag = false; // reset button flag
|
||||
char c; // to store received character
|
||||
bool char_flag = false; // a new character has been received
|
||||
/* toggle the LED with every transmitted character */
|
||||
while (true) { // infinite loop
|
||||
while (usart_received) { // echo every received character
|
||||
action = true; // action has been performed
|
||||
led_toggle(); // toggle LED
|
||||
printf("%c",usart_getchar()); // transmit receive character
|
||||
c = usart_getchar(); // store receive character
|
||||
char_flag = true; // notify character has been received
|
||||
}
|
||||
while (cdcacm_received) { // echo every received character
|
||||
action = true; // action has been performed
|
||||
led_toggle(); // toggle LED
|
||||
printf("%c",cdcacm_getchar()); // transmit receive character
|
||||
c = usart_getchar(); // store receive character
|
||||
char_flag = true; // notify character has been received
|
||||
}
|
||||
while (char_flag) {
|
||||
char_flag = false; // reset flag
|
||||
action = true; // action has been performed
|
||||
printf("%c",c); // echo receive character
|
||||
switch (c) {
|
||||
case 'r': // set red color
|
||||
ws2812b_set_rgb(0,0xff,0,0);
|
||||
break;
|
||||
case 'g': // set green color
|
||||
ws2812b_set_rgb(0,0,0xff,0);
|
||||
break;
|
||||
case 'b': // set blue color
|
||||
ws2812b_set_rgb(0,0,0,0xff);
|
||||
break;
|
||||
default: // set no color
|
||||
ws2812b_set_rgb(0,0,0,0);
|
||||
break;
|
||||
}
|
||||
ws2812b_transmit(); // transmit set color
|
||||
}
|
||||
while (button_flag) {
|
||||
button_flag = false; // reset flag
|
||||
@ -132,7 +159,7 @@ int main(void)
|
||||
led_toggle(); // toggle LED
|
||||
}
|
||||
// go to sleep if nothing had to be done, else recheck for activity
|
||||
if (action) {
|
||||
if (action) {
|
||||
action = false;
|
||||
} else {
|
||||
__WFI(); // go to sleep
|
||||
|
Loading…
Reference in New Issue
Block a user