Template for working forward

Dependencies:   mbed PinDetect

Committer:
reedas
Date:
Sat Oct 16 22:44:39 2021 +0000
Revision:
3:a14b2aa7546e
Parent:
2:ad262f2c84ca
Child:
4:d129442ea4dd
led simulation on display

Who changed what in which revision?

UserRevisionLine numberNew 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 3:a14b2aa7546e 11 Serial pc(USBTX, USBRX);
reedas 2:ad262f2c84ca 12
reedas 2:ad262f2c84ca 13 // Callback routine is interrupt activated by a debounced pb1 hit
reedas 2:ad262f2c84ca 14 void pb1_hit_callback (void)
reedas 2:ad262f2c84ca 15 {
reedas 2:ad262f2c84ca 16 counter = 0;
reedas 2:ad262f2c84ca 17 }
reedas 2:ad262f2c84ca 18
reedas 2:ad262f2c84ca 19 int readLightLevel() {
reedas 2:ad262f2c84ca 20 int lightPercent;
reedas 2:ad262f2c84ca 21 lightPercent = (lightLevel.read_u16()*100)/65535;
reedas 2:ad262f2c84ca 22 return lightPercent;
reedas 2:ad262f2c84ca 23 }
reedas 1:402b32a1025f 24
reedas 1:402b32a1025f 25 void Display_Init(void)
reedas 1:402b32a1025f 26 {
reedas 1:402b32a1025f 27
reedas 1:402b32a1025f 28 /* Set font size, foreground and background Colours */
reedas 1:402b32a1025f 29 GUI_SetFont(GUI_FONT_16B_1);
reedas 1:402b32a1025f 30 GUI_SetColor(GUI_WHITE);
reedas 1:402b32a1025f 31 GUI_SetBkColor(GUI_BLACK);
romilly 0:6beb6f498640 32
reedas 1:402b32a1025f 33 /* Clear screen and print splash screen */
reedas 1:402b32a1025f 34 GUI_Clear();
reedas 1:402b32a1025f 35 GUI_SetTextAlign(GUI_TA_HCENTER);
reedas 1:402b32a1025f 36 GUI_DispStringAt("TFT Demo", 160, 20);
reedas 1:402b32a1025f 37 }
reedas 1:402b32a1025f 38
reedas 1:402b32a1025f 39 int main()
reedas 1:402b32a1025f 40 {
reedas 2:ad262f2c84ca 41
reedas 1:402b32a1025f 42 /* Initialise EmWin driver*/
reedas 1:402b32a1025f 43 GUI_Init();
romilly 0:6beb6f498640 44
reedas 1:402b32a1025f 45 /* Initialise display */
reedas 1:402b32a1025f 46 Display_Init();
reedas 2:ad262f2c84ca 47 pb1.mode(PullUp);
reedas 2:ad262f2c84ca 48 // Delay for initial pullup to take effect
reedas 2:ad262f2c84ca 49 ThisThread::sleep_for(10);
reedas 2:ad262f2c84ca 50 // Setup Interrupt callback functions for a pb hit
reedas 2:ad262f2c84ca 51 pb1.attach_deasserted(&pb1_hit_callback);
reedas 2:ad262f2c84ca 52
reedas 2:ad262f2c84ca 53 // Start sampling pb inputs using interrupts
reedas 2:ad262f2c84ca 54 pb1.setSampleFrequency();
reedas 3:a14b2aa7546e 55 pc.printf("tft demo\r\n");
reedas 1:402b32a1025f 56
reedas 1:402b32a1025f 57
reedas 1:402b32a1025f 58 GUI_SetFont(GUI_FONT_8X16X2X2);
reedas 2:ad262f2c84ca 59 GUI_SetTextAlign(GUI_TA_HCENTER);
reedas 3:a14b2aa7546e 60 GUI_DispStringAt("Hello World!", 160, 40);
reedas 2:ad262f2c84ca 61 while(1) {
reedas 3:a14b2aa7546e 62
reedas 1:402b32a1025f 63 GUI_SetTextAlign(GUI_TA_HCENTER);
reedas 3:a14b2aa7546e 64 GUI_DispHexAt(counter, 160, 100, 2);
reedas 2:ad262f2c84ca 65 GUI_SetTextAlign(GUI_TA_HCENTER);
reedas 3:a14b2aa7546e 66 GUI_DispDecAt(counter, 160, 70, 3);
reedas 3:a14b2aa7546e 67 for(int pos = 0; pos < 8; pos++) {
reedas 3:a14b2aa7546e 68 if ((counter >> pos & 0x01) == 1) {
reedas 3:a14b2aa7546e 69 GUI_SetColor(GUI_BLUE);
reedas 3:a14b2aa7546e 70 }
reedas 3:a14b2aa7546e 71 else {
reedas 3:a14b2aa7546e 72 GUI_SetColor(GUI_DARKBLUE);
reedas 3:a14b2aa7546e 73 }
reedas 3:a14b2aa7546e 74 // GUI_FillRect(208 - (16*pos), 140, 224 - (2+16 * pos), 156);
reedas 3:a14b2aa7546e 75 GUI_FillCircle(216 - (16*pos), 148, 8);
reedas 3:a14b2aa7546e 76 }
reedas 3:a14b2aa7546e 77 GUI_SetColor(GUI_WHITE);
reedas 2:ad262f2c84ca 78 GUI_SetTextAlign(GUI_TA_HCENTER);
reedas 3:a14b2aa7546e 79 GUI_DispBinAt(counter++, 160, 160, 8);
reedas 3:a14b2aa7546e 80 GUI_DispStringAt("Light is: ", 40, 200);
reedas 2:ad262f2c84ca 81 GUI_DispDec(readLightLevel(), 3);
reedas 2:ad262f2c84ca 82 GUI_DispString("%");
reedas 2:ad262f2c84ca 83 ThisThread::sleep_for(500);
reedas 1:402b32a1025f 84
reedas 2:ad262f2c84ca 85 }
romilly 0:6beb6f498640 86 }
reedas 1:402b32a1025f 87
reedas 1:402b32a1025f 88
reedas 1:402b32a1025f 89