Ardoise magique
Dependencies: TS_DISCO_F746NG mbed LCD_DISCO_F746NG BSP_DISCO_F746NG BUTTON_GROUP RGB_matrix_Panel
Revision 13:1736b906f227, committed 2019-06-04
- Comitter:
- juliento
- Date:
- Tue Jun 04 15:19:14 2019 +0000
- Parent:
- 12:e2bb579c4455
- Commit message:
- Ardoise magique
Changed in this revision
RGB_matrix_Panel.lib | Show annotated file Show diff for this revision Revisions of this file |
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r e2bb579c4455 -r 1736b906f227 RGB_matrix_Panel.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/RGB_matrix_Panel.lib Tue Jun 04 15:19:14 2019 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/juliento/code/RGB_matrix_Panel/#cfc715e8e387
diff -r e2bb579c4455 -r 1736b906f227 main.cpp --- a/main.cpp Mon Feb 22 13:40:13 2016 +0000 +++ b/main.cpp Tue Jun 04 15:19:14 2019 +0000 @@ -8,87 +8,182 @@ using namespace Mikami; -TS_DISCO_F746NG ts_; -LCD_DISCO_F746NG lcd_; +#include "mbed.h" +#include "TS_DISCO_F746NG.h" +#include "LCD_DISCO_F746NG.h" +#include "Adafruit_GFX.h" +#include "RGBmatrixPanel.h" + +LCD_DISCO_F746NG lcd; +TS_DISCO_F746NG ts; + +Serial pc(USBTX, USBRX); + +// Matrix LEDs 32x16 +RGBmatrixPanel matrix(D1,D2,D0,A0,D3,A1,A2,D4,A3,A4,D6,A5,false); //(r1,g1,b1,r2,g2,b2,a,b,c,sclk,latch,oe,dbuf) int main() { - const int Y0 = 5; - const int X1 = 30; - const int Y1 = 100; + TS_StateTypeDef TS_State; + uint16_t x, y; + uint8_t text[30]; + uint8_t status; + uint8_t idx; + uint8_t cleared = 0; + uint8_t prev_nb_touches = 0; + int mNum; const uint32_t BACK_COLOR = 0xFF006A6C; // teal green - const uint32_t INACTIVE = BACK_COLOR & 0xE0FFFFFF; // color for inactive button - lcd_.Clear(BACK_COLOR); - - const int NUMBER_BUTTONS = 4; - const string STR[NUMBER_BUTTONS] = {"Button1", "Button2", "Button3", "Button4"}; - ButtonGroup bGroup(lcd_, ts_, 10, Y0, 66, 40, - LCD_COLOR_BLUE, BACK_COLOR, NUMBER_BUTTONS, STR, 5, 5, 3); - - const string STR_SW[2] = {"ON", "OFF"}; - ButtonGroup sw(lcd_, ts_, 10, 160, 66, 40, - LCD_COLOR_GREEN, BACK_COLOR, 2, STR_SW, 5, 0, 2); - - Button reset(lcd_, ts_, 410, Y0, 60, 40, - LCD_COLOR_BLUE, BACK_COLOR, "Reset", Font12); - reset.Draw(INACTIVE, LCD_COLOR_GRAY); + + uint8_t Xlength_case = 13, Ylength_case = 17; + + lcd.DisplayStringAt(0, LINE(5), (uint8_t *)"TOUCHSCREEN DEMO", CENTER_MODE); + wait(1); + lcd.Clear(LCD_COLOR_BLACK); + + //Initialise et configure le tactile du LCD + status = ts.Init(lcd.GetXSize(), lcd.GetYSize()); + + const string COLOR_Button[5] = {"RED", "BLUE","GREEN","RESET","GOMME"}; + ButtonGroup color(lcd, ts, 430, 30, 50, 50, + LCD_COLOR_BLUE, BACK_COLOR, 5, COLOR_Button, 5, 0, 1); + color.Draw(0, LCD_COLOR_RED); + color.Draw(1, LCD_COLOR_BLUE); + color.Draw(2, LCD_COLOR_GREEN); + color.Draw(3, LCD_COLOR_ORANGE); + color.Draw(4, LCD_COLOR_WHITE); + + matrix.begin(); + + bool blue = false; + bool red = true; + bool green = false; + bool reset = false; + bool gomme = false; + + while(1) { + + + //Grille sur écran tactile + for(int i = 0; i <= 16; i++) { + lcd.DrawHLine(0,i*Ylength_case,lcd.GetXSize()-64); + } - const string MULTI[2] = {"ON", "OFF"}; - ButtonGroup multiTouch(lcd_, ts_, 300, Y0+100, 60, 40, - LCD_COLOR_BLUE, BACK_COLOR, 2, MULTI, 5, 0, 2); - multiTouch.Draw(0, LCD_COLOR_DARKBLUE); + for(int i = 0; i <= 32; i++) { + lcd.DrawVLine(i*Xlength_case,0,lcd.GetYSize()); + } + + ts.GetState(&TS_State); - lcd_.SetTextColor(LCD_COLOR_WHITE); - lcd_.SetFont(&Font16); - lcd_.DisplayStringAt(250, Y0+80, (uint8_t *)"Multi-touch ON, OFF", LEFT_MODE); + //Condition s'il repère ou non un appui sur le LCD + if ((reset == false)&&(TS_State.touchDetected)) { + /* + // Clear lines corresponding to old touches coordinates + if (TS_State.touchDetected < prev_nb_touches) { + for (idx = (TS_State.touchDetected + 1); idx <= 5; idx++) { + lcd.ClearStringLine(idx); + } + } + */ + prev_nb_touches = TS_State.touchDetected; + + cleared = 0; - lcd_.SetFont(&Font20); - lcd_.DisplayStringAt(120, 250, (uint8_t *)"02/22 22:36", LEFT_MODE); - - DigitalOut dOut(D7); - int num; + //Nombre de doigts sur l'écran + //sprintf((char*)text, "Touches: %d", TS_State.touchDetected); + //lcd.DisplayStringAt(0, LINE(0), (uint8_t *)&text, LEFT_MODE); + + //Position de chaque doigts + for (idx = 0; idx < TS_State.touchDetected; idx++) { + x = TS_State.touchX[idx]; + y = TS_State.touchY[idx]; + sprintf((char*)text, "Touch %d: x=%d y=%d ", idx+1, x, y); + //lcd.DisplayStringAt(0, LINE(idx+1), (uint8_t *)&text, LEFT_MODE); + } + + //dessine les pixels par où on est passé + lcd.DrawPixel(TS_State.touchX[0], TS_State.touchY[0], LCD_COLOR_ORANGE); - while (true) - { - dOut = 1; - bool touched = bGroup.GetTouchedNumber(num, LCD_COLOR_DARKBLUE); - dOut = 0; - - if (touched) - { - char str[20]; - lcd_.SetFont(&Font16); - lcd_.SetTextColor(LCD_COLOR_WHITE); - sprintf(str, "Button%d pressed", num+1); - lcd_.DisplayStringAt(X1, Y1, (uint8_t *)str, LEFT_MODE); - - reset.Redraw(); + //allume les LEDs sur la matrix de LEDs + if (color.Touched(0, LCD_COLOR_DARKRED)) { + red = true; + green = false; + blue = false; + reset = false; + color.Draw(1, LCD_COLOR_BLUE); + color.Draw(2, LCD_COLOR_GREEN); + color.Draw(3, LCD_COLOR_ORANGE); + color.Draw(4, LCD_COLOR_WHITE); + } else if (color.Touched(1, LCD_COLOR_DARKBLUE)) { + blue = true; + red = false; + green = false; + reset = false; + color.Draw(0, LCD_COLOR_RED); + color.Draw(2, LCD_COLOR_GREEN); + color.Draw(3, LCD_COLOR_ORANGE); + color.Draw(4, LCD_COLOR_WHITE); + } else if (color.Touched(2, LCD_COLOR_DARKGREEN)) { + green = true; + blue = false; + red = false; + reset = false; + color.Draw(0, LCD_COLOR_RED); + color.Draw(1, LCD_COLOR_BLUE); + color.Draw(3, LCD_COLOR_ORANGE); + color.Draw(4, LCD_COLOR_WHITE); + } else if (color.Touched(3, LCD_COLOR_WHITE)) { + green = false; + blue = false; + red = false; + reset = true; + color.Draw(0, LCD_COLOR_RED); + color.Draw(1, LCD_COLOR_BLUE); + color.Draw(2, LCD_COLOR_GREEN); + } else if (color.Touched(4, LCD_COLOR_BLACK)) { + green = false; + blue = false; + red = false; + reset = false; + gomme = true; + color.Draw(0, LCD_COLOR_RED); + color.Draw(1, LCD_COLOR_BLUE); + color.Draw(2, LCD_COLOR_GREEN); + color.Draw(3, LCD_COLOR_ORANGE); + } + + if (red ==true) { + green = false; + blue = false; + gomme = false; + matrix.drawPixel((TS_State.touchX[0]/Xlength_case),(TS_State.touchY[0]/Ylength_case),matrix.Color333(7,0,0)); + + } else if (green ==true) { + red = false; + blue = false; + gomme = false; + matrix.drawPixel((TS_State.touchX[0]/Xlength_case),(TS_State.touchY[0]/Ylength_case),matrix.Color333(0,7,0)); + + } else if (blue ==true) { + green = false; + red = false; + gomme = false; + matrix.drawPixel((TS_State.touchX[0]/Xlength_case),(TS_State.touchY[0]/Ylength_case),matrix.Color333(0,0,7)); + } else if (gomme ==true) { + red = false; + green = false; + blue = false; + matrix.drawPixel((TS_State.touchX[0]/Xlength_case),(TS_State.touchY[0]/Ylength_case),matrix.Color333(0,0,0)); + } + + } else if ((reset == true)&&(!TS_State.touchDetected)&&(!cleared)) { + + //remise à zéro du LCD + cleared = 1; + reset = false; + + //remise à zéro de la matrix de LEDs + matrix.fillScreen(matrix.Color333(0, 0, 0)); } - - if (sw.Touched(0, LCD_COLOR_DARKGREEN)) - lcd_.DisplayStringAt(X1, 210, (uint8_t *)"ON ", LEFT_MODE); - if (sw.Touched(1, LCD_COLOR_DARKGREEN)) - lcd_.DisplayStringAt(X1, 210, (uint8_t *)"OFF", LEFT_MODE); - - if (reset.Touched()) - { - bGroup.Redraw(num); - reset.Draw(INACTIVE, LCD_COLOR_GRAY); - lcd_.SetFont(&Font16); - lcd_.DisplayStringAt(X1, Y1, (uint8_t *)" ", LEFT_MODE); - } - - int mNum; - if (multiTouch.GetTouchedNumber(mNum, LCD_COLOR_DARKBLUE)) - { - Button::SetMultiTouch(mNum == 0); // Set or reset multi-touch - if (mNum == 0) - lcd_.DisplayStringAt(320, Y0+150, (uint8_t *)"ON ", LEFT_MODE); - else - lcd_.DisplayStringAt(320, Y0+150, (uint8_t *)"OFF", LEFT_MODE); - } - wait(0.01f); } -} - +} \ No newline at end of file