DISCO_F746NG_Button_and_Slider_Library v1.0

Dependencies:   BSP_DISCO_F746NG LCD_DISCO_F746NG TS_DISCO_F746NG mbed

Committer:
wsteenberg
Date:
Tue Sep 25 12:41:25 2018 +0000
Revision:
0:151a96a0fc95
DISCO_F746NG_Button_and_Slider_Library v1.0

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
wsteenberg 0:151a96a0fc95 14
wsteenberg 0:151a96a0fc95 15 char char_SliderDisplayValue[4]; // String Value to display for the Slider Control value
wsteenberg 0:151a96a0fc95 16 uint16_t SliderDisplayValue_; // Variable used to access Slider Control Value in F746SLIDER.cpp
wsteenberg 0:151a96a0fc95 17
wsteenberg 0:151a96a0fc95 18 int main()
wsteenberg 0:151a96a0fc95 19 {
wsteenberg 0:151a96a0fc95 20 lcd_.Clear(LCD_COLOR_WHITE); // Set LCD Background colour
wsteenberg 0:151a96a0fc95 21
wsteenberg 0:151a96a0fc95 22 Slider sld1(lcd_, ts_, 20, 205, 150, 20, 5, 1, 20,
wsteenberg 0:151a96a0fc95 23 LCD_COLOR_BLUE, LCD_COLOR_YELLOW, 1, "Slider1", Font12); // Define sld1 slider
wsteenberg 0:151a96a0fc95 24 sld1.Render(); // Draw sld1 Slider
wsteenberg 0:151a96a0fc95 25
wsteenberg 0:151a96a0fc95 26 Slider Slider2(lcd_, ts_, 240, 205, 220, 20, 50, 1, 100,
wsteenberg 0:151a96a0fc95 27 LCD_COLOR_BLUE, LCD_COLOR_YELLOW, 2, "Slider2", Font12); // Define Slider2 slider
wsteenberg 0:151a96a0fc95 28 Slider2.Render(); // Draw Slider2 Slider
wsteenberg 0:151a96a0fc95 29
wsteenberg 0:151a96a0fc95 30 Button btn1(lcd_, ts_, 20, 50, 80, 40,
wsteenberg 0:151a96a0fc95 31 LCD_COLOR_BLUE, LCD_COLOR_YELLOW, 1, "BUTTON1", Font12); // Define btn1 button
wsteenberg 0:151a96a0fc95 32 btn1.Render(); // Draw btn1 button
wsteenberg 0:151a96a0fc95 33
wsteenberg 0:151a96a0fc95 34 Button test(lcd_, ts_, 120, 50, 80, 40,
wsteenberg 0:151a96a0fc95 35 LCD_COLOR_DARKBLUE, LCD_COLOR_GREEN, 1, "TEST", Font12); // Define test button
wsteenberg 0:151a96a0fc95 36 test.Render(); // Draw test button
wsteenberg 0:151a96a0fc95 37
wsteenberg 0:151a96a0fc95 38 Button show(lcd_, ts_, 220, 50, 80, 40,
wsteenberg 0:151a96a0fc95 39 LCD_COLOR_BROWN, LCD_COLOR_GRAY, 1, "SHOW", Font12); // Define hide button
wsteenberg 0:151a96a0fc95 40 show.Hide();
wsteenberg 0:151a96a0fc95 41
wsteenberg 0:151a96a0fc95 42 Button hide(lcd_, ts_, 220, 50, 80, 40,
wsteenberg 0:151a96a0fc95 43 LCD_COLOR_BROWN, LCD_COLOR_GRAY, 1, "HIDE", Font12); // Define hide button
wsteenberg 0:151a96a0fc95 44 hide.Render(); // Draw hide button
wsteenberg 0:151a96a0fc95 45
wsteenberg 0:151a96a0fc95 46 Button button3D(lcd_, ts_, 320, 50, 120, 40,
wsteenberg 0:151a96a0fc95 47 LCD_COLOR_BLUE, LCD_COLOR_YELLOW, 2, "3D BUTTON", Font12); // Define button3D button
wsteenberg 0:151a96a0fc95 48 button3D.Render(); // Draw 3Dbutton button
wsteenberg 0:151a96a0fc95 49
wsteenberg 0:151a96a0fc95 50 lcd_.SetTextColor(LCD_COLOR_BLACK); // Set Text colour to Black
wsteenberg 0:151a96a0fc95 51 lcd_.SetFont(&Font12); // Font size 12
wsteenberg 0:151a96a0fc95 52 lcd_.DisplayStringAt(5, 5, (uint8_t *)"Button / Slider driver for DISCO_F746", LEFT_MODE); // Display main header text
wsteenberg 0:151a96a0fc95 53 lcd_.DisplayStringAt(5, 20, (uint8_t *)"Button example", LEFT_MODE); // Display secondary header text
wsteenberg 0:151a96a0fc95 54 lcd_.DisplayStringAt(5, 135, (uint8_t *)"Slider example", LEFT_MODE); // Display secondary header text
wsteenberg 0:151a96a0fc95 55
wsteenberg 0:151a96a0fc95 56 while (true) // Main program loop
wsteenberg 0:151a96a0fc95 57 {
wsteenberg 0:151a96a0fc95 58 if (sld1.Moved()) // Check if sld1 Slider was touched and run instructions if true
wsteenberg 0:151a96a0fc95 59 {
wsteenberg 0:151a96a0fc95 60 lcd_.SetTextColor(LCD_COLOR_BLACK);
wsteenberg 0:151a96a0fc95 61 lcd_.FillRect(130, 140, 80, 40); // Draw border to display Slider Control Value
wsteenberg 0:151a96a0fc95 62 lcd_.SetTextColor(LCD_COLOR_WHITE);
wsteenberg 0:151a96a0fc95 63 lcd_.FillRect(140, 145, 60, 30); // Draw border to display Slider Control Value
wsteenberg 0:151a96a0fc95 64
wsteenberg 0:151a96a0fc95 65 sprintf(char_SliderDisplayValue, "%3d", (int) SliderDisplayValue_); // Convert integer to text
wsteenberg 0:151a96a0fc95 66 lcd_.SetFont(&Font12); // Set Font size
wsteenberg 0:151a96a0fc95 67 lcd_.SetTextColor(LCD_COLOR_BLACK); // Set Font colour
wsteenberg 0:151a96a0fc95 68 lcd_.DisplayStringAt(150, 155, (uint8_t *)char_SliderDisplayValue, LEFT_MODE); // Write Slider Control Value to the LCD
wsteenberg 0:151a96a0fc95 69
wsteenberg 0:151a96a0fc95 70 if (SliderDisplayValue_ < 10) // Slider Control Value decision
wsteenberg 0:151a96a0fc95 71 {
wsteenberg 0:151a96a0fc95 72 lcd_.DisplayStringAt(60, 190, (uint8_t *)" ", LEFT_MODE); // Overwrite previous text
wsteenberg 0:151a96a0fc95 73 lcd_.DisplayStringAt(60, 190, (uint8_t *)"SLIDER1 < 50%", LEFT_MODE); // Write text to LCD
wsteenberg 0:151a96a0fc95 74 }
wsteenberg 0:151a96a0fc95 75 else if (SliderDisplayValue_ == 10) // Slider Control Value decision
wsteenberg 0:151a96a0fc95 76 {
wsteenberg 0:151a96a0fc95 77 lcd_.DisplayStringAt(60, 190, (uint8_t *)" ", LEFT_MODE); // Overwrite previous text
wsteenberg 0:151a96a0fc95 78 lcd_.DisplayStringAt(60, 190, (uint8_t *)"SLIDER1 = 50%", LEFT_MODE); // Write text to LCD
wsteenberg 0:151a96a0fc95 79 }
wsteenberg 0:151a96a0fc95 80 else // Slider Control Value decision
wsteenberg 0:151a96a0fc95 81 {
wsteenberg 0:151a96a0fc95 82 lcd_.DisplayStringAt(60, 190, (uint8_t *)" ", LEFT_MODE); // Overwrite previous text
wsteenberg 0:151a96a0fc95 83 lcd_.DisplayStringAt(60, 190, (uint8_t *)"SLIDER1 > 50%", LEFT_MODE); // Write text to LCD
wsteenberg 0:151a96a0fc95 84 }
wsteenberg 0:151a96a0fc95 85 } // End sld1 instructions
wsteenberg 0:151a96a0fc95 86
wsteenberg 0:151a96a0fc95 87 if (Slider2.Moved()) // Check if Slider2 Slider was touched and run instructions if true
wsteenberg 0:151a96a0fc95 88 {
wsteenberg 0:151a96a0fc95 89 lcd_.SetTextColor(LCD_COLOR_BLACK);
wsteenberg 0:151a96a0fc95 90 lcd_.FillRect(390, 140, 80, 40); // Draw border to display Slider Control Value
wsteenberg 0:151a96a0fc95 91 lcd_.SetTextColor(LCD_COLOR_WHITE);
wsteenberg 0:151a96a0fc95 92 lcd_.FillRect(400, 145, 60, 30); // Draw border to display Slider Control Value
wsteenberg 0:151a96a0fc95 93
wsteenberg 0:151a96a0fc95 94 sprintf(char_SliderDisplayValue, "%3d", (int) SliderDisplayValue_); // Convert integer to text
wsteenberg 0:151a96a0fc95 95 lcd_.SetFont(&Font12); // Set Font size
wsteenberg 0:151a96a0fc95 96 lcd_.SetTextColor(LCD_COLOR_BLACK); // Set Font colour
wsteenberg 0:151a96a0fc95 97 lcd_.DisplayStringAt(415, 155, (uint8_t *)char_SliderDisplayValue, LEFT_MODE); // Write Slider Control Value to the LCD
wsteenberg 0:151a96a0fc95 98 }
wsteenberg 0:151a96a0fc95 99
wsteenberg 0:151a96a0fc95 100
wsteenberg 0:151a96a0fc95 101 if (btn1.Press()) // Check if btn1 button was touched and run instructions if true
wsteenberg 0:151a96a0fc95 102 {
wsteenberg 0:151a96a0fc95 103 lcd_.SetFont(&Font12);
wsteenberg 0:151a96a0fc95 104 lcd_.SetTextColor(LCD_COLOR_BLACK);
wsteenberg 0:151a96a0fc95 105 lcd_.DisplayStringAt(5, 110, (uint8_t *)"Button1 pressed", LEFT_MODE);
wsteenberg 0:151a96a0fc95 106 wait(0.5);
wsteenberg 0:151a96a0fc95 107 lcd_.DisplayStringAt(5, 110, (uint8_t *)" ", LEFT_MODE);
wsteenberg 0:151a96a0fc95 108 } // End btn1 button instructions
wsteenberg 0:151a96a0fc95 109
wsteenberg 0:151a96a0fc95 110 if (test.Press()) // Check if test button was touched and run instructions if true
wsteenberg 0:151a96a0fc95 111 {
wsteenberg 0:151a96a0fc95 112 lcd_.SetFont(&Font12);
wsteenberg 0:151a96a0fc95 113 lcd_.SetTextColor(LCD_COLOR_BLACK);
wsteenberg 0:151a96a0fc95 114 lcd_.DisplayStringAt(5, 110, (uint8_t *)"TEST pressed", LEFT_MODE);
wsteenberg 0:151a96a0fc95 115 wait(0.5);
wsteenberg 0:151a96a0fc95 116 lcd_.DisplayStringAt(5, 110, (uint8_t *)" ", LEFT_MODE);
wsteenberg 0:151a96a0fc95 117
wsteenberg 0:151a96a0fc95 118 } // End test button instructions
wsteenberg 0:151a96a0fc95 119
wsteenberg 0:151a96a0fc95 120 if (hide.Press()) // Check if hide button was touched and run instructions if true
wsteenberg 0:151a96a0fc95 121 {
wsteenberg 0:151a96a0fc95 122 lcd_.SetFont(&Font12);
wsteenberg 0:151a96a0fc95 123 lcd_.SetTextColor(LCD_COLOR_BLACK);
wsteenberg 0:151a96a0fc95 124 lcd_.DisplayStringAt(5, 110, (uint8_t *)"Hide pressed - Hide other buttons", LEFT_MODE);
wsteenberg 0:151a96a0fc95 125 btn1.Hide(); // Hide btn1 button
wsteenberg 0:151a96a0fc95 126 test.Hide(); // Hide test button
wsteenberg 0:151a96a0fc95 127 hide.Hide();
wsteenberg 0:151a96a0fc95 128 show.Render();
wsteenberg 0:151a96a0fc95 129 wait(0.5);
wsteenberg 0:151a96a0fc95 130 lcd_.DisplayStringAt(5, 110, (uint8_t *)" ", LEFT_MODE);
wsteenberg 0:151a96a0fc95 131 } // End hide button instructions
wsteenberg 0:151a96a0fc95 132
wsteenberg 0:151a96a0fc95 133 if (show.Press()) // Check if hide button was touched and run instructions if true
wsteenberg 0:151a96a0fc95 134 {
wsteenberg 0:151a96a0fc95 135 lcd_.SetFont(&Font12);
wsteenberg 0:151a96a0fc95 136 lcd_.SetTextColor(LCD_COLOR_BLACK);
wsteenberg 0:151a96a0fc95 137 lcd_.DisplayStringAt(5, 110, (uint8_t *)"UNHIDE pressed - Restore other buttons", LEFT_MODE);
wsteenberg 0:151a96a0fc95 138 wait(0.5);
wsteenberg 0:151a96a0fc95 139 lcd_.DisplayStringAt(5, 110, (uint8_t *)" ", LEFT_MODE);
wsteenberg 0:151a96a0fc95 140 show.Hide(); // Hide show button before drawing new button in same place
wsteenberg 0:151a96a0fc95 141 hide.Render(); // Draw hide button after hiding button in same position
wsteenberg 0:151a96a0fc95 142 btn1.Render(); // Draw btn1 button
wsteenberg 0:151a96a0fc95 143 test.Render(); // Draw test button
wsteenberg 0:151a96a0fc95 144
wsteenberg 0:151a96a0fc95 145 }
wsteenberg 0:151a96a0fc95 146
wsteenberg 0:151a96a0fc95 147 if (button3D.Press()) // Check if 3Dbutton button was touched and run instructions if true
wsteenberg 0:151a96a0fc95 148 {
wsteenberg 0:151a96a0fc95 149 lcd_.SetFont(&Font12);
wsteenberg 0:151a96a0fc95 150 lcd_.SetTextColor(LCD_COLOR_BLACK);
wsteenberg 0:151a96a0fc95 151 lcd_.DisplayStringAt(5, 110, (uint8_t *)"3D Button pressed", LEFT_MODE);
wsteenberg 0:151a96a0fc95 152 wait(0.5);
wsteenberg 0:151a96a0fc95 153 lcd_.DisplayStringAt(5, 110, (uint8_t *)" ", LEFT_MODE);
wsteenberg 0:151a96a0fc95 154 } // End 3D button instructions
wsteenberg 0:151a96a0fc95 155
wsteenberg 0:151a96a0fc95 156 wait(0.02f);
wsteenberg 0:151a96a0fc95 157 } // End Main program loop
wsteenberg 0:151a96a0fc95 158 } // End Main program