Decide right or left for you
Dependencies: mbed LCD_DISCO_F469NI TS_DISCO_F469NI BSP_DISCO_F469NI
Project description
Nothing more simple: this is a high quality project allowing the user to download cosmos random to find a direction in your life when you have no idea where to go.
The decisions are restrained to RIGHT or LEFT.
Features
- Cosmos download via SCP (secure copy using SSH for data transfer).
- Countdown displays the remaining downloading time.
- Pick randomly RIGHT or LEFT and display the choice with an arrow and text.
- Track the number of decision.
- Home button to download again the cosmos.
Instructions
- Plug the board to USB to supply the board with some electricity (if using USB micro ('USB USER' plug) you must put the jumper JP2 on 'USB', if using USB mini ('USB ST-LINK' plug) you must put the jumper JP2 on 'STLK').
- Wait a very short moment so the board boot and the touchscreen initialize (a green screen should appears).
- Touch anywhere on the touchscreen to start the cosmos downloading.
- Observe the random direction extracted from the cosmos.
- Touch again as many time as needed to decide again (the number of decision is displayed in the top left corner). NB: each cosmos download contains an infinity of random direction.
- If desired you can download again the cosmos via the home screen by touching the home button.
- If needed (the cosmos may be busy or broken), you can reset the board and go back on the home screen by pushing the black button or by plugging/unplugging the USB power cable.
Disclaimer
Injuries
Any injury resulting from an abnormal of the decider code cannot be imputed to the author of this code.
Joke
This is a fantasy, don't take it for serious.
main.cpp
- Committer:
- nicovv44
- Date:
- 2019-05-17
- Revision:
- 5:ef44b84a149f
- Parent:
- 4:0f34a6ad1f4c
- Child:
- 6:70ef7ee9e4f3
- Child:
- 9:5c2f112a2b0b
- Child:
- 11:a91282fae08b
File content as of revision 5:ef44b84a149f:
#include "mbed.h" #include "TS_DISCO_F469NI.h" #include "LCD_DISCO_F469NI.h" #include <stdio.h> #include <stdlib.h> enum { LEFT, RIGHT }; LCD_DISCO_F469NI lcd; TS_DISCO_F469NI ts; int main() { TS_StateTypeDef TS_State; uint16_t x, y; uint8_t direction, decisionCounter, countdown; uint8_t firstDecision; uint8_t text[30] = ""; uint8_t status; uint8_t fingerPress; time_t t; Point points[4]; /* Intializes random number generator */ srand((unsigned) time(&t)); BSP_LCD_SetFont(&Font24); status = ts.Init(lcd.GetXSize(), lcd.GetYSize()); home: decisionCounter = 1; firstDecision = 1; fingerPress = 0; if (status != TS_OK) { lcd.Clear(LCD_COLOR_RED); wait(0.1);//apparently we have to wait a bit after Clear lcd.SetBackColor(LCD_COLOR_RED); lcd.SetTextColor(LCD_COLOR_WHITE); lcd.DisplayStringAt(0, LINE(5), (uint8_t *)"TOUCHSCREEN INIT FAIL", CENTER_MODE); goto end; } else { lcd.Clear(LCD_COLOR_DARKGREEN); wait(0.1);//apparently we have to wait a bit after Clear lcd.SetBackColor(LCD_COLOR_DARKGREEN); lcd.SetTextColor(LCD_COLOR_WHITE); //lcd.DisplayStringAt(0, LINE(5), (uint8_t *)"TOUCHSCREEN INIT OK", CENTER_MODE); lcd.DisplayStringAt(0, LINE(6), (uint8_t *)"READY TO CHOSE YOUR LIFE", CENTER_MODE); lcd.DisplayStringAt(0, LINE(8), (uint8_t *)"TOUCH TO DECIDE", CENTER_MODE); } lcd.SetBackColor(LCD_COLOR_LIGHTGRAY); lcd.SetTextColor(LCD_COLOR_BLACK); while(1) { ts.GetState(&TS_State); if (TS_State.touchDetected && fingerPress==0) {//finger lands fingerPress = 1; /* get landing poosition */ x = TS_State.touchX[0]; y = TS_State.touchY[0]; /* countdown */ if(firstDecision){ firstDecision = 0; lcd.Clear(LCD_COLOR_LIGHTGRAY); wait(0.1);//apparently we have to wait a bit after Clear for(countdown=10 ; countdown>0 ; countdown--){ lcd.ClearStringLine(10); sprintf((char*)text, "Downloading cosmos energy..."); lcd.DisplayStringAt(0, LINE(6), (uint8_t *)&text, CENTER_MODE); sprintf((char*)text, "%d", countdown); lcd.DisplayStringAt(0, LINE(10), (uint8_t *)&text, CENTER_MODE); wait(1.0); } } else{//finger lands, not the first decision if(x>lcd.GetXSize()-100 && y<100) goto home; } lcd.Clear(LCD_COLOR_LIGHTGRAY); wait(0.1);//apparently we have to wait a bit after Clear /* display return home button */ lcd.SetTextColor(LCD_COLOR_DARKGREEN); lcd.FillRect(lcd.GetXSize()-100,0,100,100); lcd.SetBackColor(LCD_COLOR_DARKGREEN); lcd.SetTextColor(LCD_COLOR_WHITE); wait(0.01); sprintf((char*)text, "HOME"); lcd.DisplayStringAt(10, LINE(1)+10, (uint8_t *)&text, RIGHT_MODE); /* other colors */ lcd.SetBackColor(LCD_COLOR_LIGHTGRAY); lcd.SetTextColor(LCD_COLOR_BLACK); /* decision counter */ sprintf((char*)text, "Decision#:%d", decisionCounter++); lcd.DisplayStringAt(0, LINE(0), (uint8_t *)&text, LEFT_MODE); /* decision of direction*/ direction = rand()%2; switch(direction) { case LEFT: sprintf((char*)text, "LEFT"); //horizontal bar lcd.FillRect(250,300,300,20); //top diagonal points[0].X=250; points[0].Y=300; points[1].X=250+80; points[1].Y=300-70; points[2].X=250+20+80; points[2].Y=300-70; points[3].X=250+20; points[3].Y=300; lcd.FillPolygon(points, 4); //bottom diagonal points[0].X=250; points[0].Y=300+20; points[1].X=250+80; points[1].Y=300+70+20; points[2].X=250+20+80; points[2].Y=300+70+20; points[3].X=250+20; points[3].Y=300+20; lcd.FillPolygon(points, 4); break; case RIGHT: sprintf((char*)text, "RIGHT"); //horizontal bar lcd.FillRect(250,300,300,20); //top diagonal points[0].X=250+300-20; points[0].Y=300; points[1].X=250+300-20-80; points[1].Y=300-70; points[2].X=250+300-80; points[2].Y=300-70; points[3].X=250+300; points[3].Y=300; lcd.FillPolygon(points, 4); //bottom diagonal points[0].X=250+300-20; points[0].Y=300+20; points[1].X=250+300-20-80; points[1].Y=300+70+20; points[2].X=250+300-80; points[2].Y=300+70+20; points[3].X=250+300; points[3].Y=300+20; lcd.FillPolygon(points, 4); break; } //display text of direction lcd.DisplayStringAt(0, LINE(6), (uint8_t *)&text, CENTER_MODE); } if(!TS_State.touchDetected && fingerPress==1) {//finger takes off fingerPress = 0; } if(!TS_State.touchDetected) {//finger is flying } if(TS_State.touchDetected) {//finger is on the ground } } end: {} }