![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Ardoise magique
Dependencies: TS_DISCO_F746NG mbed LCD_DISCO_F746NG BSP_DISCO_F746NG BUTTON_GROUP RGB_matrix_Panel
main.cpp@11:74a4d2c3870e, 2016-02-18 (annotated)
- Committer:
- MikamiUitOpen
- Date:
- Thu Feb 18 10:05:00 2016 +0000
- Revision:
- 11:74a4d2c3870e
- Parent:
- 10:e2e65b7039f4
- Child:
- 12:e2bb579c4455
12
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 | 11:74a4d2c3870e | 4 | // 2016/02/18, 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 | 4:201e97957618 | 33 | Button Large(lcd_, ts_, 280, 100, 120, 60, |
MikamiUitOpen | 6:2736b38c1d73 | 34 | LCD_COLOR_GREEN, BACK_COLOR, "LARGE", Font24); |
MikamiUitOpen | 3:edc98882d63a | 35 | |
MikamiUitOpen | 0:35af280527cf | 36 | Button reset(lcd_, ts_, 410, Y0, 60, 40, |
MikamiUitOpen | 6:2736b38c1d73 | 37 | LCD_COLOR_BLUE, BACK_COLOR, "Reset", Font12); |
MikamiUitOpen | 6:2736b38c1d73 | 38 | reset.Draw(INACTIVE, LCD_COLOR_GRAY); |
MikamiUitOpen | 0:35af280527cf | 39 | |
MikamiUitOpen | 0:35af280527cf | 40 | lcd_.SetTextColor(LCD_COLOR_WHITE); |
MikamiUitOpen | 10:e2e65b7039f4 | 41 | lcd_.DisplayStringAt(100, 260, (uint8_t *)"02/17 15:27", LEFT_MODE); |
MikamiUitOpen | 6:2736b38c1d73 | 42 | int num; |
MikamiUitOpen | 0:35af280527cf | 43 | while (true) |
MikamiUitOpen | 0:35af280527cf | 44 | { |
MikamiUitOpen | 0:35af280527cf | 45 | if (bGroup.GetTouchedNumber(num, LCD_COLOR_DARKBLUE)) |
MikamiUitOpen | 0:35af280527cf | 46 | { |
MikamiUitOpen | 0:35af280527cf | 47 | char str[20]; |
MikamiUitOpen | 0:35af280527cf | 48 | lcd_.SetFont(&Font16); |
MikamiUitOpen | 0:35af280527cf | 49 | lcd_.SetTextColor(LCD_COLOR_WHITE); |
MikamiUitOpen | 0:35af280527cf | 50 | sprintf(str, "Button%d pressed", num+1); |
MikamiUitOpen | 0:35af280527cf | 51 | lcd_.DisplayStringAt(X1, Y1, (uint8_t *)str, LEFT_MODE); |
MikamiUitOpen | 0:35af280527cf | 52 | |
MikamiUitOpen | 0:35af280527cf | 53 | reset.Redraw(); |
MikamiUitOpen | 0:35af280527cf | 54 | } |
MikamiUitOpen | 0:35af280527cf | 55 | |
MikamiUitOpen | 4:201e97957618 | 56 | if (sw.Touched(0, LCD_COLOR_DARKGREEN)) |
MikamiUitOpen | 4:201e97957618 | 57 | lcd_.DisplayStringAt(X1, 210, (uint8_t *)"ON ", LEFT_MODE); |
MikamiUitOpen | 4:201e97957618 | 58 | if (sw.Touched(1, LCD_COLOR_DARKGREEN)) |
MikamiUitOpen | 4:201e97957618 | 59 | lcd_.DisplayStringAt(X1, 210, (uint8_t *)"OFF", LEFT_MODE); |
MikamiUitOpen | 4:201e97957618 | 60 | |
MikamiUitOpen | 0:35af280527cf | 61 | if (reset.Touched()) |
MikamiUitOpen | 0:35af280527cf | 62 | { |
MikamiUitOpen | 0:35af280527cf | 63 | bGroup.Redraw(num); |
MikamiUitOpen | 6:2736b38c1d73 | 64 | reset.Draw(INACTIVE, LCD_COLOR_GRAY); |
MikamiUitOpen | 0:35af280527cf | 65 | lcd_.SetFont(&Font16); |
MikamiUitOpen | 0:35af280527cf | 66 | lcd_.DisplayStringAt(X1, Y1, (uint8_t *)" ", LEFT_MODE); |
MikamiUitOpen | 0:35af280527cf | 67 | } |
MikamiUitOpen | 0:35af280527cf | 68 | wait(0.5f); |
MikamiUitOpen | 0:35af280527cf | 69 | } |
MikamiUitOpen | 0:35af280527cf | 70 | } |