a
Dependencies: TS_F746 LCD_746 LbBSP746NG GUI_746
main.cpp@2:e11266cb3ba5, 2019-10-09 (annotated)
- Committer:
- fundokukiri
- Date:
- Wed Oct 09 12:24:16 2019 +0000
- Revision:
- 2:e11266cb3ba5
- Parent:
- 1:dcda1118b4ef
- Child:
- 3:451a7e2f7928
GUI-746
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
wsteenberg | 0:151a96a0fc95 | 1 | //--------------------------------------------------------------- |
wsteenberg | 0:151a96a0fc95 | 2 | // |
wsteenberg | 0:151a96a0fc95 | 3 | // Demo program for |
wsteenberg | 0:151a96a0fc95 | 4 | // F746_Button and Slider library |
wsteenberg | 0:151a96a0fc95 | 5 | // |
wsteenberg | 0:151a96a0fc95 | 6 | //--------------------------------------------------------------- |
wsteenberg | 0:151a96a0fc95 | 7 | #include "mbed.h" |
wsteenberg | 0:151a96a0fc95 | 8 | #include "F746_BUTTON.hpp" |
wsteenberg | 0:151a96a0fc95 | 9 | |
wsteenberg | 0:151a96a0fc95 | 10 | TS_DISCO_F746NG ts_; |
wsteenberg | 0:151a96a0fc95 | 11 | LCD_DISCO_F746NG lcd_; |
wsteenberg | 0:151a96a0fc95 | 12 | |
tquang14 | 1:dcda1118b4ef | 13 | InterruptIn button1(USER_BUTTON); |
tquang14 | 1:dcda1118b4ef | 14 | volatile bool button1_pressed = false; // Used in the main loop |
tquang14 | 1:dcda1118b4ef | 15 | volatile bool button1_enabled = true; // Used for debouncing |
tquang14 | 1:dcda1118b4ef | 16 | Timeout button1_timeout; // Used for debouncing |
tquang14 | 1:dcda1118b4ef | 17 | |
tquang14 | 1:dcda1118b4ef | 18 | void button1_enabled_cb(void) |
tquang14 | 1:dcda1118b4ef | 19 | { |
tquang14 | 1:dcda1118b4ef | 20 | button1_enabled = true; |
tquang14 | 1:dcda1118b4ef | 21 | } |
tquang14 | 1:dcda1118b4ef | 22 | |
tquang14 | 1:dcda1118b4ef | 23 | // ISR handling button pressed event |
tquang14 | 1:dcda1118b4ef | 24 | void button1_onpressed_cb(void) |
tquang14 | 1:dcda1118b4ef | 25 | { |
tquang14 | 1:dcda1118b4ef | 26 | if (button1_enabled) { // Disabled while the button is bouncing |
tquang14 | 1:dcda1118b4ef | 27 | button1_enabled = false; |
tquang14 | 1:dcda1118b4ef | 28 | button1_pressed = true; // To be read by the main loop |
tquang14 | 1:dcda1118b4ef | 29 | button1_timeout.attach(callback(button1_enabled_cb), 0.3); // Debounce time 300 ms |
tquang14 | 1:dcda1118b4ef | 30 | } |
tquang14 | 1:dcda1118b4ef | 31 | } |
wsteenberg | 0:151a96a0fc95 | 32 | |
wsteenberg | 0:151a96a0fc95 | 33 | char char_SliderDisplayValue[4]; // String Value to display for the Slider Control value |
wsteenberg | 0:151a96a0fc95 | 34 | uint16_t SliderDisplayValue_; // Variable used to access Slider Control Value in F746SLIDER.cpp |
tquang14 | 1:dcda1118b4ef | 35 | DigitalOut led(LED1); |
wsteenberg | 0:151a96a0fc95 | 36 | int main() |
wsteenberg | 0:151a96a0fc95 | 37 | { |
wsteenberg | 0:151a96a0fc95 | 38 | lcd_.Clear(LCD_COLOR_WHITE); // Set LCD Background colour |
wsteenberg | 0:151a96a0fc95 | 39 | |
wsteenberg | 0:151a96a0fc95 | 40 | Button btn1(lcd_, ts_, 20, 50, 80, 40, |
wsteenberg | 0:151a96a0fc95 | 41 | LCD_COLOR_BLUE, LCD_COLOR_YELLOW, 1, "BUTTON1", Font12); // Define btn1 button |
wsteenberg | 0:151a96a0fc95 | 42 | btn1.Render(); // Draw btn1 button |
tquang14 | 1:dcda1118b4ef | 43 | button1.fall(callback(button1_onpressed_cb)); // Attach ISR to handle button press event |
wsteenberg | 0:151a96a0fc95 | 44 | |
tquang14 | 1:dcda1118b4ef | 45 | int idx = 0; // Just for printf below |
wsteenberg | 0:151a96a0fc95 | 46 | while (true) // Main program loop |
tquang14 | 1:dcda1118b4ef | 47 | { // End sld1 instructions |
tquang14 | 1:dcda1118b4ef | 48 | |
wsteenberg | 0:151a96a0fc95 | 49 | if (btn1.Press()) // Check if btn1 button was touched and run instructions if true |
wsteenberg | 0:151a96a0fc95 | 50 | { |
wsteenberg | 0:151a96a0fc95 | 51 | lcd_.SetFont(&Font12); |
wsteenberg | 0:151a96a0fc95 | 52 | lcd_.SetTextColor(LCD_COLOR_BLACK); |
tquang14 | 1:dcda1118b4ef | 53 | led = !led; |
wsteenberg | 0:151a96a0fc95 | 54 | wait(0.5); |
wsteenberg | 0:151a96a0fc95 | 55 | lcd_.DisplayStringAt(5, 110, (uint8_t *)" ", LEFT_MODE); |
wsteenberg | 0:151a96a0fc95 | 56 | } // End btn1 button instructions |
tquang14 | 1:dcda1118b4ef | 57 | if (button1_pressed) { // Set when button is pressed |
tquang14 | 1:dcda1118b4ef | 58 | button1_pressed = false; |
tquang14 | 1:dcda1118b4ef | 59 | led = !led; |
tquang14 | 1:dcda1118b4ef | 60 | char *tmp; |
tquang14 | 1:dcda1118b4ef | 61 | sprintf(tmp, "Button pressed %d", idx++); |
wsteenberg | 0:151a96a0fc95 | 62 | wait(0.5); |
tquang14 | 1:dcda1118b4ef | 63 | lcd_.SetFont(&Font20); |
tquang14 | 1:dcda1118b4ef | 64 | |
tquang14 | 1:dcda1118b4ef | 65 | lcd_.DisplayStringAt(5, 160, (uint8_t *)tmp, LEFT_MODE); |
wsteenberg | 0:151a96a0fc95 | 66 | wait(0.5); |
tquang14 | 1:dcda1118b4ef | 67 | } // End 3D button instructions |
wsteenberg | 0:151a96a0fc95 | 68 | wait(0.02f); |
wsteenberg | 0:151a96a0fc95 | 69 | } // End Main program loop |
wsteenberg | 0:151a96a0fc95 | 70 | } // End Main program |