Example of Button class and ButtonGroup class for DISCO-F746NG. DISCO-F746NG 用の,Button クラス,ButtonGroup クラスの使用例.
Dependencies: BSP_DISCO_F746NG BUTTON_GROUP LCD_DISCO_F746NG TS_DISCO_F746NG mbed
main.cpp@12:e2bb579c4455, 2016-02-22 (annotated)
- Committer:
- MikamiUitOpen
- Date:
- Mon Feb 22 13:40:13 2016 +0000
- Revision:
- 12:e2bb579c4455
- Parent:
- 11:74a4d2c3870e
13
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MikamiUitOpen | 0:35af280527cf | 1 | //--------------------------------------------------------------- |
MikamiUitOpen | 0:35af280527cf | 2 | // Demo program of Button class and ButtonGroup class |
MikamiUitOpen | 0:35af280527cf | 3 | // |
MikamiUitOpen | 12:e2bb579c4455 | 4 | // 2016/02/22, Copyright (c) 2016 MIKAMI, Naoki |
MikamiUitOpen | 0:35af280527cf | 5 | //--------------------------------------------------------------- |
MikamiUitOpen | 0:35af280527cf | 6 | |
MikamiUitOpen | 0:35af280527cf | 7 | #include "button_group.hpp" |
MikamiUitOpen | 0:35af280527cf | 8 | |
MikamiUitOpen | 0:35af280527cf | 9 | using namespace Mikami; |
MikamiUitOpen | 0:35af280527cf | 10 | |
MikamiUitOpen | 0:35af280527cf | 11 | TS_DISCO_F746NG ts_; |
MikamiUitOpen | 0:35af280527cf | 12 | LCD_DISCO_F746NG lcd_; |
MikamiUitOpen | 0:35af280527cf | 13 | |
MikamiUitOpen | 0:35af280527cf | 14 | int main() |
MikamiUitOpen | 0:35af280527cf | 15 | { |
MikamiUitOpen | 0:35af280527cf | 16 | const int Y0 = 5; |
MikamiUitOpen | 4:201e97957618 | 17 | const int X1 = 30; |
MikamiUitOpen | 4:201e97957618 | 18 | const int Y1 = 100; |
MikamiUitOpen | 0:35af280527cf | 19 | |
MikamiUitOpen | 6:2736b38c1d73 | 20 | const uint32_t BACK_COLOR = 0xFF006A6C; // teal green |
MikamiUitOpen | 6:2736b38c1d73 | 21 | const uint32_t INACTIVE = BACK_COLOR & 0xE0FFFFFF; // color for inactive button |
MikamiUitOpen | 6:2736b38c1d73 | 22 | lcd_.Clear(BACK_COLOR); |
MikamiUitOpen | 0:35af280527cf | 23 | |
MikamiUitOpen | 0:35af280527cf | 24 | const int NUMBER_BUTTONS = 4; |
MikamiUitOpen | 1:83147f0d63ea | 25 | const string STR[NUMBER_BUTTONS] = {"Button1", "Button2", "Button3", "Button4"}; |
MikamiUitOpen | 0:35af280527cf | 26 | ButtonGroup bGroup(lcd_, ts_, 10, Y0, 66, 40, |
MikamiUitOpen | 6:2736b38c1d73 | 27 | LCD_COLOR_BLUE, BACK_COLOR, NUMBER_BUTTONS, STR, 5, 5, 3); |
MikamiUitOpen | 0:35af280527cf | 28 | |
MikamiUitOpen | 4:201e97957618 | 29 | const string STR_SW[2] = {"ON", "OFF"}; |
MikamiUitOpen | 4:201e97957618 | 30 | ButtonGroup sw(lcd_, ts_, 10, 160, 66, 40, |
MikamiUitOpen | 6:2736b38c1d73 | 31 | LCD_COLOR_GREEN, BACK_COLOR, 2, STR_SW, 5, 0, 2); |
MikamiUitOpen | 4:201e97957618 | 32 | |
MikamiUitOpen | 0:35af280527cf | 33 | Button reset(lcd_, ts_, 410, Y0, 60, 40, |
MikamiUitOpen | 6:2736b38c1d73 | 34 | LCD_COLOR_BLUE, BACK_COLOR, "Reset", Font12); |
MikamiUitOpen | 6:2736b38c1d73 | 35 | reset.Draw(INACTIVE, LCD_COLOR_GRAY); |
MikamiUitOpen | 0:35af280527cf | 36 | |
MikamiUitOpen | 12:e2bb579c4455 | 37 | const string MULTI[2] = {"ON", "OFF"}; |
MikamiUitOpen | 12:e2bb579c4455 | 38 | ButtonGroup multiTouch(lcd_, ts_, 300, Y0+100, 60, 40, |
MikamiUitOpen | 12:e2bb579c4455 | 39 | LCD_COLOR_BLUE, BACK_COLOR, 2, MULTI, 5, 0, 2); |
MikamiUitOpen | 12:e2bb579c4455 | 40 | multiTouch.Draw(0, LCD_COLOR_DARKBLUE); |
MikamiUitOpen | 12:e2bb579c4455 | 41 | |
MikamiUitOpen | 0:35af280527cf | 42 | lcd_.SetTextColor(LCD_COLOR_WHITE); |
MikamiUitOpen | 12:e2bb579c4455 | 43 | lcd_.SetFont(&Font16); |
MikamiUitOpen | 12:e2bb579c4455 | 44 | lcd_.DisplayStringAt(250, Y0+80, (uint8_t *)"Multi-touch ON, OFF", LEFT_MODE); |
MikamiUitOpen | 12:e2bb579c4455 | 45 | |
MikamiUitOpen | 12:e2bb579c4455 | 46 | lcd_.SetFont(&Font20); |
MikamiUitOpen | 12:e2bb579c4455 | 47 | lcd_.DisplayStringAt(120, 250, (uint8_t *)"02/22 22:36", LEFT_MODE); |
MikamiUitOpen | 12:e2bb579c4455 | 48 | |
MikamiUitOpen | 12:e2bb579c4455 | 49 | DigitalOut dOut(D7); |
MikamiUitOpen | 6:2736b38c1d73 | 50 | int num; |
MikamiUitOpen | 12:e2bb579c4455 | 51 | |
MikamiUitOpen | 0:35af280527cf | 52 | while (true) |
MikamiUitOpen | 0:35af280527cf | 53 | { |
MikamiUitOpen | 12:e2bb579c4455 | 54 | dOut = 1; |
MikamiUitOpen | 12:e2bb579c4455 | 55 | bool touched = bGroup.GetTouchedNumber(num, LCD_COLOR_DARKBLUE); |
MikamiUitOpen | 12:e2bb579c4455 | 56 | dOut = 0; |
MikamiUitOpen | 12:e2bb579c4455 | 57 | |
MikamiUitOpen | 12:e2bb579c4455 | 58 | if (touched) |
MikamiUitOpen | 0:35af280527cf | 59 | { |
MikamiUitOpen | 0:35af280527cf | 60 | char str[20]; |
MikamiUitOpen | 0:35af280527cf | 61 | lcd_.SetFont(&Font16); |
MikamiUitOpen | 0:35af280527cf | 62 | lcd_.SetTextColor(LCD_COLOR_WHITE); |
MikamiUitOpen | 0:35af280527cf | 63 | sprintf(str, "Button%d pressed", num+1); |
MikamiUitOpen | 0:35af280527cf | 64 | lcd_.DisplayStringAt(X1, Y1, (uint8_t *)str, LEFT_MODE); |
MikamiUitOpen | 0:35af280527cf | 65 | |
MikamiUitOpen | 0:35af280527cf | 66 | reset.Redraw(); |
MikamiUitOpen | 0:35af280527cf | 67 | } |
MikamiUitOpen | 0:35af280527cf | 68 | |
MikamiUitOpen | 4:201e97957618 | 69 | if (sw.Touched(0, LCD_COLOR_DARKGREEN)) |
MikamiUitOpen | 4:201e97957618 | 70 | lcd_.DisplayStringAt(X1, 210, (uint8_t *)"ON ", LEFT_MODE); |
MikamiUitOpen | 4:201e97957618 | 71 | if (sw.Touched(1, LCD_COLOR_DARKGREEN)) |
MikamiUitOpen | 4:201e97957618 | 72 | lcd_.DisplayStringAt(X1, 210, (uint8_t *)"OFF", LEFT_MODE); |
MikamiUitOpen | 4:201e97957618 | 73 | |
MikamiUitOpen | 0:35af280527cf | 74 | if (reset.Touched()) |
MikamiUitOpen | 0:35af280527cf | 75 | { |
MikamiUitOpen | 0:35af280527cf | 76 | bGroup.Redraw(num); |
MikamiUitOpen | 6:2736b38c1d73 | 77 | reset.Draw(INACTIVE, LCD_COLOR_GRAY); |
MikamiUitOpen | 0:35af280527cf | 78 | lcd_.SetFont(&Font16); |
MikamiUitOpen | 0:35af280527cf | 79 | lcd_.DisplayStringAt(X1, Y1, (uint8_t *)" ", LEFT_MODE); |
MikamiUitOpen | 0:35af280527cf | 80 | } |
MikamiUitOpen | 12:e2bb579c4455 | 81 | |
MikamiUitOpen | 12:e2bb579c4455 | 82 | int mNum; |
MikamiUitOpen | 12:e2bb579c4455 | 83 | if (multiTouch.GetTouchedNumber(mNum, LCD_COLOR_DARKBLUE)) |
MikamiUitOpen | 12:e2bb579c4455 | 84 | { |
MikamiUitOpen | 12:e2bb579c4455 | 85 | Button::SetMultiTouch(mNum == 0); // Set or reset multi-touch |
MikamiUitOpen | 12:e2bb579c4455 | 86 | if (mNum == 0) |
MikamiUitOpen | 12:e2bb579c4455 | 87 | lcd_.DisplayStringAt(320, Y0+150, (uint8_t *)"ON ", LEFT_MODE); |
MikamiUitOpen | 12:e2bb579c4455 | 88 | else |
MikamiUitOpen | 12:e2bb579c4455 | 89 | lcd_.DisplayStringAt(320, Y0+150, (uint8_t *)"OFF", LEFT_MODE); |
MikamiUitOpen | 12:e2bb579c4455 | 90 | } |
MikamiUitOpen | 12:e2bb579c4455 | 91 | wait(0.01f); |
MikamiUitOpen | 0:35af280527cf | 92 | } |
MikamiUitOpen | 0:35af280527cf | 93 | } |
MikamiUitOpen | 12:e2bb579c4455 | 94 |