![](/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@0:35af280527cf, 2015-11-23 (annotated)
- Committer:
- MikamiUitOpen
- Date:
- Mon Nov 23 01:27:04 2015 +0000
- Revision:
- 0:35af280527cf
- Child:
- 1:83147f0d63ea
1
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 | 0:35af280527cf | 4 | // 2015/11/23, Copyright (c) 2015 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 | 0:35af280527cf | 17 | const int X1 = 50; |
MikamiUitOpen | 0:35af280527cf | 18 | const int Y1 = 200; |
MikamiUitOpen | 0:35af280527cf | 19 | |
MikamiUitOpen | 0:35af280527cf | 20 | uint32_t backColor = 0xFF006A6C; // teal green |
MikamiUitOpen | 0:35af280527cf | 21 | uint32_t inActive = backColor & 0xE0FFFFFF; // color for inactive button |
MikamiUitOpen | 0:35af280527cf | 22 | lcd_.Clear(backColor); |
MikamiUitOpen | 0:35af280527cf | 23 | |
MikamiUitOpen | 0:35af280527cf | 24 | const int NUMBER_BUTTONS = 4; |
MikamiUitOpen | 0:35af280527cf | 25 | string str[NUMBER_BUTTONS] = {"Button1", "Button2", "Button3", "Button4"}; |
MikamiUitOpen | 0:35af280527cf | 26 | ButtonGroup bGroup(lcd_, ts_, 10, Y0, 66, 40, |
MikamiUitOpen | 0:35af280527cf | 27 | LCD_COLOR_BLUE, backColor, NUMBER_BUTTONS, str, 5, 5, 3); |
MikamiUitOpen | 0:35af280527cf | 28 | |
MikamiUitOpen | 0:35af280527cf | 29 | Button reset(lcd_, ts_, 410, Y0, 60, 40, |
MikamiUitOpen | 0:35af280527cf | 30 | LCD_COLOR_BLUE, backColor, "Reset", Font12); |
MikamiUitOpen | 0:35af280527cf | 31 | reset.Draw(inActive, LCD_COLOR_GRAY); |
MikamiUitOpen | 0:35af280527cf | 32 | |
MikamiUitOpen | 0:35af280527cf | 33 | lcd_.SetTextColor(LCD_COLOR_WHITE); |
MikamiUitOpen | 0:35af280527cf | 34 | while (true) |
MikamiUitOpen | 0:35af280527cf | 35 | { |
MikamiUitOpen | 0:35af280527cf | 36 | int num; |
MikamiUitOpen | 0:35af280527cf | 37 | if (bGroup.GetTouchedNumber(num, LCD_COLOR_DARKBLUE)) |
MikamiUitOpen | 0:35af280527cf | 38 | { |
MikamiUitOpen | 0:35af280527cf | 39 | char str[20]; |
MikamiUitOpen | 0:35af280527cf | 40 | lcd_.SetFont(&Font16); |
MikamiUitOpen | 0:35af280527cf | 41 | lcd_.SetTextColor(LCD_COLOR_WHITE); |
MikamiUitOpen | 0:35af280527cf | 42 | sprintf(str, "Button%d pressed", num+1); |
MikamiUitOpen | 0:35af280527cf | 43 | lcd_.DisplayStringAt(X1, Y1, (uint8_t *)str, LEFT_MODE); |
MikamiUitOpen | 0:35af280527cf | 44 | |
MikamiUitOpen | 0:35af280527cf | 45 | reset.Redraw(); |
MikamiUitOpen | 0:35af280527cf | 46 | } |
MikamiUitOpen | 0:35af280527cf | 47 | |
MikamiUitOpen | 0:35af280527cf | 48 | if (reset.Touched()) |
MikamiUitOpen | 0:35af280527cf | 49 | { |
MikamiUitOpen | 0:35af280527cf | 50 | bGroup.Redraw(num); |
MikamiUitOpen | 0:35af280527cf | 51 | reset.Draw(inActive, LCD_COLOR_GRAY); |
MikamiUitOpen | 0:35af280527cf | 52 | lcd_.SetFont(&Font16); |
MikamiUitOpen | 0:35af280527cf | 53 | lcd_.DisplayStringAt(X1, Y1, (uint8_t *)" ", LEFT_MODE); |
MikamiUitOpen | 0:35af280527cf | 54 | } |
MikamiUitOpen | 0:35af280527cf | 55 | wait(0.5f); |
MikamiUitOpen | 0:35af280527cf | 56 | } |
MikamiUitOpen | 0:35af280527cf | 57 | } |
MikamiUitOpen | 0:35af280527cf | 58 |