Andrew Reed
/
CITY1082-TFT-basic_sw2_ctr
Sw2 key press counter and display to tft
Revision 2:f7100947de37, committed 2019-11-26
- Comitter:
- reedas
- Date:
- Tue Nov 26 09:14:00 2019 +0000
- Parent:
- 1:402b32a1025f
- Commit message:
- Switch SW2 key press counter
Changed in this revision
PinDetect.lib | Show annotated file Show diff for this revision Revisions of this file |
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 402b32a1025f -r f7100947de37 PinDetect.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PinDetect.lib Tue Nov 26 09:14:00 2019 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/reedas/code/PinDetect/#d552d2899765
diff -r 402b32a1025f -r f7100947de37 main.cpp --- a/main.cpp Tue Nov 19 10:04:48 2019 +0000 +++ b/main.cpp Tue Nov 26 09:14:00 2019 +0000 @@ -1,8 +1,19 @@ -/* Hello World! for the TextLCD Enhanced Library*/ +/* Hello World! for the Emwin TFT Library */ #include "mbed.h" #include "GUI.h" #include "cy8ckit_028_tft.h" +#include "PinDetect.h" + +PinDetect pb1(SWITCH2); +volatile bool keypressed = true; + +// Callback routine is interrupt activated by a debounced pb1 hit +void pb1_hit_callback (void) +{ + keypressed = true; +} + void Display_Init(void) { @@ -20,17 +31,33 @@ int main() { + uint8 counter = 0; /* Initialise EmWin driver*/ GUI_Init(); /* Initialise display */ Display_Init(); + pb1.mode(PullUp); + // Delay for initial pullup to take effect + ThisThread::sleep_for(10); + // Setup Interrupt callback functions for a pb hit + pb1.attach_deasserted(&pb1_hit_callback); + + // Start sampling pb inputs using interrupts + pb1.setSampleFrequency(); GUI_SetFont(GUI_FONT_8X16X2X2); - GUI_SetTextAlign(GUI_TA_HCENTER); - GUI_DispStringAt("Hello World!", 160, 200); - + GUI_SetTextAlign(GUI_TA_HCENTER); + GUI_DispStringAt("Hello World!", 160, 200); + while(1) { + if(keypressed == true) { + GUI_SetTextAlign(GUI_TA_HCENTER); + GUI_DispBinAt(counter++, 160, 100, 8); + ThisThread::sleep_for(100); + keypressed = false; + } + } }