
Interfaçage NeoPixel Ring 12, LPRO MECSE, Arnaud A.
Dependencies: lcd neoPixelRing12 view2 BSP_DISCO_F746NG view1 button
Diff: main.cpp
- Revision:
- 6:91e478ee227e
- Parent:
- 5:e8f8a8037256
- Child:
- 7:1887c4e4b5de
--- a/main.cpp Wed Nov 20 11:33:58 2019 +0100 +++ b/main.cpp Thu May 28 15:32:34 2020 +0000 @@ -1,40 +1,92 @@ #include "mbed.h" -#include "stm32746g_discovery_lcd.h" +#include "Thread.h" +#include "rtos_idle.h" +#include "mbed_critical.h" + +#define USE_CRITICAL_SECTION_LOCK 1 // Set 0 to see race condition + +InterruptIn button(USER_BUTTON) +; +DigitalOut myled(D8); +DigitalOut led1(LED1); + +void bit0(){ + myled = 1; + wait_ns(190); + myled = 0; + wait_ns(740); +} + +void bit1(){ + myled = 1; + wait_ns(600); + myled = 0; + wait_ns(600); +} + +void rst(){ + myled=0; + wait_us(70); +} + +void setLights(bool state, int nbOfLeds){ + if(state){ + for(int i=0; i<24*nbOfLeds; i++){ + bit1(); + } + } + else{ + for(int i=0; i<24*nbOfLeds; i++){ + bit0(); + } + } +} + +void pressed() +{ + led1=1; + //rst(); + //setLights(true, 1); + //setLights(false, 5); + //setLights(true, 1); + for(int i=0; i<16; i++){ + bit0(); + } + /*setLights(true, 1); + setLights(false, 1); + setLights(true, 1);*/ + rst(); + +} + +void released() + +{ + led1=0; +} + int main() { - BSP_LCD_Init(); - BSP_LCD_LayerDefaultInit(LTDC_ACTIVE_LAYER, LCD_FB_START_ADDRESS); - BSP_LCD_SelectLayer(LTDC_ACTIVE_LAYER); - - while (1) { - BSP_LCD_Clear(LCD_COLOR_BLACK); - BSP_LCD_SetFont(&LCD_DEFAULT_FONT); - BSP_LCD_SetBackColor(LCD_COLOR_WHITE); - BSP_LCD_SetTextColor(LCD_COLOR_DARKBLUE); - - BSP_LCD_DisplayStringAt(0, 1, (uint8_t *)"MBED EXAMPLE", CENTER_MODE); - HAL_Delay(2000); - - BSP_LCD_SetBackColor(LCD_COLOR_BLACK); - BSP_LCD_SetTextColor(LCD_COLOR_ORANGE); - BSP_LCD_DisplayStringAt(0, 100, (uint8_t *)"DISCOVERY STM32F746NG", CENTER_MODE); - HAL_Delay(2000); + int i=0; + button.rise(&pressed); + button.fall(&released); + /*while(1){ + myled = 1; + wait_ns(350); + myled = 0; + }*/ + //while(1){ + //CriticalSectionLock lock; + //bit0(); + //CriticalSectionLock unlock; + setLights(false, 1); + rst(); + setLights(false, 5); + setLights(true, 2); + setLights(true, 4); + wait(100.0); + //} +} - BSP_LCD_Clear(LCD_COLOR_GREEN); - BSP_LCD_SetTextColor(LCD_COLOR_BLUE); - BSP_LCD_DrawRect(10, 20, 50, 50); - BSP_LCD_SetTextColor(LCD_COLOR_BROWN); - BSP_LCD_DrawCircle(80, 80, 50); - BSP_LCD_SetTextColor(LCD_COLOR_YELLOW); - BSP_LCD_DrawEllipse(150, 150, 50, 100); - BSP_LCD_SetTextColor(LCD_COLOR_RED); - BSP_LCD_FillCircle(200, 200, 40); - HAL_Delay(2000); - BSP_LCD_SetBackColor(LCD_COLOR_GREEN); - BSP_LCD_SetTextColor(LCD_COLOR_CYAN); - BSP_LCD_DisplayStringAt(0, 6, (uint8_t *)"HAVE FUN !!!", RIGHT_MODE); - HAL_Delay(2000); - } -}