Josh Bam
/
CITY3032-Template
Template for working forward
main.cpp@2:ad262f2c84ca, 2021-10-16 (annotated)
- Committer:
- reedas
- Date:
- Sat Oct 16 08:10:02 2021 +0000
- Revision:
- 2:ad262f2c84ca
- Parent:
- 1:402b32a1025f
- Child:
- 3:a14b2aa7546e
binary/digital/hex counter and light level display
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 | #include "PinDetect.h" |
reedas | 2:ad262f2c84ca | 7 | |
reedas | 2:ad262f2c84ca | 8 | PinDetect pb1(SWITCH2); |
reedas | 2:ad262f2c84ca | 9 | uint8 counter = 0; |
reedas | 2:ad262f2c84ca | 10 | AnalogIn lightLevel(P10_0); |
reedas | 2:ad262f2c84ca | 11 | |
reedas | 2:ad262f2c84ca | 12 | // Callback routine is interrupt activated by a debounced pb1 hit |
reedas | 2:ad262f2c84ca | 13 | void pb1_hit_callback (void) |
reedas | 2:ad262f2c84ca | 14 | { |
reedas | 2:ad262f2c84ca | 15 | counter = 0; |
reedas | 2:ad262f2c84ca | 16 | } |
reedas | 2:ad262f2c84ca | 17 | |
reedas | 2:ad262f2c84ca | 18 | int readLightLevel() { |
reedas | 2:ad262f2c84ca | 19 | int lightPercent; |
reedas | 2:ad262f2c84ca | 20 | lightPercent = (lightLevel.read_u16()*100)/65535; |
reedas | 2:ad262f2c84ca | 21 | return lightPercent; |
reedas | 2:ad262f2c84ca | 22 | } |
reedas | 1:402b32a1025f | 23 | |
reedas | 1:402b32a1025f | 24 | void Display_Init(void) |
reedas | 1:402b32a1025f | 25 | { |
reedas | 1:402b32a1025f | 26 | |
reedas | 1:402b32a1025f | 27 | /* Set font size, foreground and background Colours */ |
reedas | 1:402b32a1025f | 28 | GUI_SetFont(GUI_FONT_16B_1); |
reedas | 1:402b32a1025f | 29 | GUI_SetColor(GUI_WHITE); |
reedas | 1:402b32a1025f | 30 | GUI_SetBkColor(GUI_BLACK); |
romilly | 0:6beb6f498640 | 31 | |
reedas | 1:402b32a1025f | 32 | /* Clear screen and print splash screen */ |
reedas | 1:402b32a1025f | 33 | GUI_Clear(); |
reedas | 1:402b32a1025f | 34 | GUI_SetTextAlign(GUI_TA_HCENTER); |
reedas | 1:402b32a1025f | 35 | GUI_DispStringAt("TFT Demo", 160, 20); |
reedas | 1:402b32a1025f | 36 | } |
reedas | 1:402b32a1025f | 37 | |
reedas | 1:402b32a1025f | 38 | int main() |
reedas | 1:402b32a1025f | 39 | { |
reedas | 2:ad262f2c84ca | 40 | |
reedas | 1:402b32a1025f | 41 | /* Initialise EmWin driver*/ |
reedas | 1:402b32a1025f | 42 | GUI_Init(); |
romilly | 0:6beb6f498640 | 43 | |
reedas | 1:402b32a1025f | 44 | /* Initialise display */ |
reedas | 1:402b32a1025f | 45 | Display_Init(); |
reedas | 2:ad262f2c84ca | 46 | pb1.mode(PullUp); |
reedas | 2:ad262f2c84ca | 47 | // Delay for initial pullup to take effect |
reedas | 2:ad262f2c84ca | 48 | ThisThread::sleep_for(10); |
reedas | 2:ad262f2c84ca | 49 | // Setup Interrupt callback functions for a pb hit |
reedas | 2:ad262f2c84ca | 50 | pb1.attach_deasserted(&pb1_hit_callback); |
reedas | 2:ad262f2c84ca | 51 | |
reedas | 2:ad262f2c84ca | 52 | // Start sampling pb inputs using interrupts |
reedas | 2:ad262f2c84ca | 53 | pb1.setSampleFrequency(); |
reedas | 1:402b32a1025f | 54 | |
reedas | 1:402b32a1025f | 55 | |
reedas | 1:402b32a1025f | 56 | GUI_SetFont(GUI_FONT_8X16X2X2); |
reedas | 2:ad262f2c84ca | 57 | GUI_SetTextAlign(GUI_TA_HCENTER); |
reedas | 2:ad262f2c84ca | 58 | GUI_DispStringAt("Hello World!", 160, 200); |
reedas | 2:ad262f2c84ca | 59 | while(1) { |
reedas | 1:402b32a1025f | 60 | GUI_SetTextAlign(GUI_TA_HCENTER); |
reedas | 2:ad262f2c84ca | 61 | GUI_DispHexAt(counter, 160, 70, 2); |
reedas | 2:ad262f2c84ca | 62 | GUI_SetTextAlign(GUI_TA_HCENTER); |
reedas | 2:ad262f2c84ca | 63 | GUI_DispDecAt(counter, 160, 130, 3); |
reedas | 2:ad262f2c84ca | 64 | GUI_SetTextAlign(GUI_TA_HCENTER); |
reedas | 2:ad262f2c84ca | 65 | GUI_DispBinAt(counter++, 160, 100, 8); |
reedas | 2:ad262f2c84ca | 66 | GUI_DispStringAt("Light is: ", 10, 160); |
reedas | 2:ad262f2c84ca | 67 | GUI_DispDec(readLightLevel(), 3); |
reedas | 2:ad262f2c84ca | 68 | GUI_DispString("%"); |
reedas | 2:ad262f2c84ca | 69 | ThisThread::sleep_for(500); |
reedas | 1:402b32a1025f | 70 | |
reedas | 2:ad262f2c84ca | 71 | } |
romilly | 0:6beb6f498640 | 72 | } |
reedas | 1:402b32a1025f | 73 | |
reedas | 1:402b32a1025f | 74 | |
reedas | 1:402b32a1025f | 75 |