Wakeup Light with touch user interface, anti-aliased Font, SD card access and RTC usage on STM32F746NG-DISCO board
Dependencies: BSP_DISCO_F746NG_patch_fixed LCD_DISCO_F746NG TS_DISCO_F746NG FATFileSystem TinyJpgDec_interwork mbed-src
LED.cpp
- Committer:
- the_sz
- Date:
- 2015-10-29
- Revision:
- 3:ecf7f1f8d749
- Parent:
- 1:35e2ad5cd1fe
- Child:
- 5:13c70bcde7f6
File content as of revision 3:ecf7f1f8d749:
#include "WakeupLight.h" #define COLOR_CREATE(_RED_,_GREEN_,_BLUE_,_WHITE_) (_RED_ | (_GREEN_ << 8) | (_BLUE_ << 16) | (_WHITE_ <<24)) #define COLOR_RED(_COLOR_) (_COLOR_ & 0xFF) #define COLOR_GREEN(_COLOR_) ((_COLOR_ >> 8) & 0xFF) #define COLOR_BLUE(_COLOR_) ((_COLOR_ >> 16) & 0xFF) #define COLOR_WHITE(_COLOR_) ((_COLOR_ >> 24) & 0xFF) #define LED_PERIOD 10 PwmOut ledBlue(PB_15); PwmOut ledRed(PH_6); PwmOut ledGreen(PB_4); PwmOut ledWhite(PA_15); Ticker ledTicker; int32_t ledAnimationStep; LED_ANIMATION_ENUM ledAnimation; void LED_SetColor(int32_t color) { DPrintfCore("LED_SetColor: 0x%08X.\r\n",color); ledRed.write(1.0 * COLOR_RED(color) / 255.0); ledGreen.write(1.0 * COLOR_GREEN(color) / 255.0); ledBlue.write(1.0 * COLOR_BLUE(color) / 255.0); ledWhite.write(1.0 * COLOR_WHITE(color) / 255.0); } void LED_Callback() { int32_t color; DPrintfCore("LED_Callback: Animation: %u, Step: %u.\r\n",ledAnimation,ledAnimationStep); if (ledAnimation==LAE_WAKEUP) { if (ledAnimationStep<255) { ledAnimationStep++; color=COLOR_CREATE((ledAnimationStep/2),ledAnimationStep,0,0); LED_SetColor(color); } else if (ledAnimationStep<(255+180)) { ledAnimationStep++; color=COLOR_CREATE(128,255,0,(ledAnimationStep-255)); LED_SetColor(color); } } else if (ledAnimation==LAE_OFF) { float red; float green; float blue; float white; uint32_t redInt; uint32_t greenInt; uint32_t blueInt; uint32_t whiteInt; red=ledRed.read(); if (red>0.0) red-=0.001; red=MAX(red,0.0); redInt=(int32_t)(red*255.0); green=ledGreen.read(); if (green>0.0) green-=0.001; green=MAX(green,0.0); greenInt=(int32_t)(green*255.0); blue=ledBlue.read(); if (blue>0) blue-=0.001; blue=MAX(blue,0.0); blueInt=(int32_t)(blue*255.0); white=ledWhite.read(); if (white>0) white-=0.001; white=MAX(white,0.0); whiteInt=(int32_t)(white*255.0); color=COLOR_CREATE(redInt,greenInt,blueInt,whiteInt); LED_SetColor(color); } } void LED_StartAnimation(LED_ANIMATION_ENUM animation) { ledAnimationStep=0; ledAnimation=animation; } void LED_Init(void) { ledRed.period_ms(LED_PERIOD); ledGreen.period_ms(LED_PERIOD); ledBlue.period_ms(LED_PERIOD); ledWhite.period_ms(LED_PERIOD); LED_SetColor(COLOR_CREATE(0,0,0,0)); LED_StartAnimation(LAE_NONE); ledTicker.attach(&LED_Callback,0.05); }