![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
RGB Lights
main.cpp@6:528d74136b6a, 2021-11-03 (annotated)
- Committer:
- reedas
- Date:
- Wed Nov 03 11:24:16 2021 +0000
- Revision:
- 6:528d74136b6a
- Parent:
- 5:9a03cb84a60c
- Child:
- 7:bd8ad736bd09
3/11/21 light sensor
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
reedas | 2:ad262f2c84ca | 1 | /* Hello World! for the Emwin TFT Library */ |
reedas | 1:402b32a1025f | 2 | |
romilly | 0:6beb6f498640 | 3 | #include "mbed.h" |
reedas | 1:402b32a1025f | 4 | #include "GUI.h" |
reedas | 1:402b32a1025f | 5 | #include "cy8ckit_028_tft.h" |
reedas | 2:ad262f2c84ca | 6 | |
reedas | 5:9a03cb84a60c | 7 | #define LED_DIAMETER (32) |
reedas | 4:d129442ea4dd | 8 | #define LED_RADIUS (LED_DIAMETER/2) |
reedas | 4:d129442ea4dd | 9 | #define DISPLAY_X (320) |
reedas | 4:d129442ea4dd | 10 | #define DISPLAY_Y (240) |
reedas | 4:d129442ea4dd | 11 | #define NUMLEDS_X (DISPLAY_X/LED_DIAMETER) |
reedas | 4:d129442ea4dd | 12 | #define NUMLEDS_Y (DISPLAY_Y/LED_DIAMETER) |
reedas | 4:d129442ea4dd | 13 | #define LED_OFF (0) |
reedas | 4:d129442ea4dd | 14 | #define LED_ON (1) |
reedas | 4:d129442ea4dd | 15 | #define TITLE_OFFSET (16+LED_RADIUS) |
reedas | 1:402b32a1025f | 16 | |
reedas | 6:528d74136b6a | 17 | AnalogIn lightLevel(P10_0); |
reedas | 6:528d74136b6a | 18 | |
reedas | 1:402b32a1025f | 19 | void Display_Init(void) |
reedas | 1:402b32a1025f | 20 | { |
reedas | 4:d129442ea4dd | 21 | /* Initialise EmWin driver*/ |
reedas | 4:d129442ea4dd | 22 | GUI_Init(); |
reedas | 1:402b32a1025f | 23 | |
reedas | 1:402b32a1025f | 24 | /* Set font size, foreground and background Colours */ |
reedas | 6:528d74136b6a | 25 | GUI_SetFont(GUI_FONT_24B_1); |
reedas | 1:402b32a1025f | 26 | GUI_SetColor(GUI_WHITE); |
reedas | 1:402b32a1025f | 27 | GUI_SetBkColor(GUI_BLACK); |
romilly | 0:6beb6f498640 | 28 | |
reedas | 1:402b32a1025f | 29 | /* Clear screen and print splash screen */ |
reedas | 1:402b32a1025f | 30 | GUI_Clear(); |
reedas | 1:402b32a1025f | 31 | GUI_SetTextAlign(GUI_TA_HCENTER); |
reedas | 6:528d74136b6a | 32 | GUI_DispStringAt("CITY3032 Light Level", 160, 0); |
reedas | 1:402b32a1025f | 33 | } |
reedas | 1:402b32a1025f | 34 | |
reedas | 1:402b32a1025f | 35 | int main() |
reedas | 1:402b32a1025f | 36 | { |
reedas | 1:402b32a1025f | 37 | /* Initialise display */ |
reedas | 1:402b32a1025f | 38 | Display_Init(); |
reedas | 2:ad262f2c84ca | 39 | |
reedas | 6:528d74136b6a | 40 | printf("light level\r\n"); |
reedas | 1:402b32a1025f | 41 | |
reedas | 6:528d74136b6a | 42 | GUI_SetFont(GUI_FONT_24B_1); |
reedas | 6:528d74136b6a | 43 | GUI_SetColor(GUI_WHITE); |
reedas | 6:528d74136b6a | 44 | while(true) { |
reedas | 6:528d74136b6a | 45 | int lightPercent; |
reedas | 6:528d74136b6a | 46 | lightPercent = (lightLevel.read_u16()*100)/65535; |
reedas | 6:528d74136b6a | 47 | printf("light level is %d\r\n",lightPercent); |
reedas | 6:528d74136b6a | 48 | ThisThread::sleep_for(1000); |
reedas | 4:d129442ea4dd | 49 | } |
reedas | 6:528d74136b6a | 50 | |
romilly | 0:6beb6f498640 | 51 | } |
reedas | 1:402b32a1025f | 52 | |
reedas | 1:402b32a1025f | 53 | |
reedas | 1:402b32a1025f | 54 |