a

Dependencies:   TS_F746 LCD_746 LbBSP746NG GUI_746

Committer:
tquang14
Date:
Tue Oct 08 09:11:23 2019 +0000
Revision:
1:dcda1118b4ef
Parent:
0:151a96a0fc95
Child:
2:e11266cb3ba5
aaaaa

Who changed what in which revision?

UserRevisionLine numberNew 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 #include "F746_SLIDER.hpp"
wsteenberg 0:151a96a0fc95 10
wsteenberg 0:151a96a0fc95 11 TS_DISCO_F746NG ts_;
wsteenberg 0:151a96a0fc95 12 LCD_DISCO_F746NG lcd_;
wsteenberg 0:151a96a0fc95 13
tquang14 1:dcda1118b4ef 14 InterruptIn button1(USER_BUTTON);
tquang14 1:dcda1118b4ef 15 volatile bool button1_pressed = false; // Used in the main loop
tquang14 1:dcda1118b4ef 16 volatile bool button1_enabled = true; // Used for debouncing
tquang14 1:dcda1118b4ef 17 Timeout button1_timeout; // Used for debouncing
tquang14 1:dcda1118b4ef 18
tquang14 1:dcda1118b4ef 19 void button1_enabled_cb(void)
tquang14 1:dcda1118b4ef 20 {
tquang14 1:dcda1118b4ef 21 button1_enabled = true;
tquang14 1:dcda1118b4ef 22 }
tquang14 1:dcda1118b4ef 23
tquang14 1:dcda1118b4ef 24 // ISR handling button pressed event
tquang14 1:dcda1118b4ef 25 void button1_onpressed_cb(void)
tquang14 1:dcda1118b4ef 26 {
tquang14 1:dcda1118b4ef 27 if (button1_enabled) { // Disabled while the button is bouncing
tquang14 1:dcda1118b4ef 28 button1_enabled = false;
tquang14 1:dcda1118b4ef 29 button1_pressed = true; // To be read by the main loop
tquang14 1:dcda1118b4ef 30 button1_timeout.attach(callback(button1_enabled_cb), 0.3); // Debounce time 300 ms
tquang14 1:dcda1118b4ef 31 }
tquang14 1:dcda1118b4ef 32 }
wsteenberg 0:151a96a0fc95 33
wsteenberg 0:151a96a0fc95 34 char char_SliderDisplayValue[4]; // String Value to display for the Slider Control value
wsteenberg 0:151a96a0fc95 35 uint16_t SliderDisplayValue_; // Variable used to access Slider Control Value in F746SLIDER.cpp
tquang14 1:dcda1118b4ef 36 DigitalOut led(LED1);
wsteenberg 0:151a96a0fc95 37 int main()
wsteenberg 0:151a96a0fc95 38 {
wsteenberg 0:151a96a0fc95 39 lcd_.Clear(LCD_COLOR_WHITE); // Set LCD Background colour
wsteenberg 0:151a96a0fc95 40
wsteenberg 0:151a96a0fc95 41 Button btn1(lcd_, ts_, 20, 50, 80, 40,
wsteenberg 0:151a96a0fc95 42 LCD_COLOR_BLUE, LCD_COLOR_YELLOW, 1, "BUTTON1", Font12); // Define btn1 button
wsteenberg 0:151a96a0fc95 43 btn1.Render(); // Draw btn1 button
tquang14 1:dcda1118b4ef 44 button1.fall(callback(button1_onpressed_cb)); // Attach ISR to handle button press event
wsteenberg 0:151a96a0fc95 45
tquang14 1:dcda1118b4ef 46 int idx = 0; // Just for printf below
wsteenberg 0:151a96a0fc95 47 while (true) // Main program loop
tquang14 1:dcda1118b4ef 48 { // End sld1 instructions
tquang14 1:dcda1118b4ef 49
wsteenberg 0:151a96a0fc95 50 if (btn1.Press()) // Check if btn1 button was touched and run instructions if true
wsteenberg 0:151a96a0fc95 51 {
wsteenberg 0:151a96a0fc95 52 lcd_.SetFont(&Font12);
wsteenberg 0:151a96a0fc95 53 lcd_.SetTextColor(LCD_COLOR_BLACK);
wsteenberg 0:151a96a0fc95 54 lcd_.DisplayStringAt(5, 110, (uint8_t *)"Button1 pressed", LEFT_MODE);
tquang14 1:dcda1118b4ef 55 led = !led;
wsteenberg 0:151a96a0fc95 56 wait(0.5);
wsteenberg 0:151a96a0fc95 57 lcd_.DisplayStringAt(5, 110, (uint8_t *)" ", LEFT_MODE);
wsteenberg 0:151a96a0fc95 58 } // End btn1 button instructions
tquang14 1:dcda1118b4ef 59 if (button1_pressed) { // Set when button is pressed
tquang14 1:dcda1118b4ef 60 button1_pressed = false;
tquang14 1:dcda1118b4ef 61 led = !led;
tquang14 1:dcda1118b4ef 62 char *tmp;
tquang14 1:dcda1118b4ef 63 sprintf(tmp, "Button pressed %d", idx++);
wsteenberg 0:151a96a0fc95 64 wait(0.5);
tquang14 1:dcda1118b4ef 65 lcd_.SetFont(&Font20);
tquang14 1:dcda1118b4ef 66
tquang14 1:dcda1118b4ef 67 lcd_.DisplayStringAt(5, 160, (uint8_t *)tmp, LEFT_MODE);
wsteenberg 0:151a96a0fc95 68 wait(0.5);
tquang14 1:dcda1118b4ef 69 } // End 3D button instructions
wsteenberg 0:151a96a0fc95 70 wait(0.02f);
wsteenberg 0:151a96a0fc95 71 } // End Main program loop
wsteenberg 0:151a96a0fc95 72 } // End Main program