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

  1. 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').
  2. Wait a very short moment so the board boot and the touchscreen initialize (a green screen should appears).
  3. Touch anywhere on the touchscreen to start the cosmos downloading.
  4. Observe the random direction extracted from the cosmos.
  5. 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.
  6. If desired you can download again the cosmos via the home screen by touching the home button.
  7. 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.

Committer:
nicovv44
Date:
Thu May 16 13:00:16 2019 +0000
Revision:
4:0f34a6ad1f4c
Parent:
0:0e730157c767
Child:
5:ef44b84a149f
Ready to decide.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bcostm 0:0e730157c767 1 #include "mbed.h"
bcostm 0:0e730157c767 2 #include "TS_DISCO_F469NI.h"
bcostm 0:0e730157c767 3 #include "LCD_DISCO_F469NI.h"
nicovv44 4:0f34a6ad1f4c 4 #include <stdio.h>
nicovv44 4:0f34a6ad1f4c 5 #include <stdlib.h>
nicovv44 4:0f34a6ad1f4c 6
nicovv44 4:0f34a6ad1f4c 7 enum {
nicovv44 4:0f34a6ad1f4c 8 LEFT,
nicovv44 4:0f34a6ad1f4c 9 RIGHT
nicovv44 4:0f34a6ad1f4c 10 };
nicovv44 4:0f34a6ad1f4c 11
bcostm 0:0e730157c767 12
bcostm 0:0e730157c767 13 LCD_DISCO_F469NI lcd;
bcostm 0:0e730157c767 14 TS_DISCO_F469NI ts;
bcostm 0:0e730157c767 15
bcostm 0:0e730157c767 16 int main()
bcostm 0:0e730157c767 17 {
bcostm 0:0e730157c767 18 TS_StateTypeDef TS_State;
nicovv44 4:0f34a6ad1f4c 19 uint8_t direction, decisionCounter=1;
nicovv44 4:0f34a6ad1f4c 20 uint8_t text[30] = "";
bcostm 0:0e730157c767 21 uint8_t status;
nicovv44 4:0f34a6ad1f4c 22 uint8_t fingerPress = 0;
nicovv44 4:0f34a6ad1f4c 23 time_t t;
nicovv44 4:0f34a6ad1f4c 24 Point points[4];
nicovv44 4:0f34a6ad1f4c 25
nicovv44 4:0f34a6ad1f4c 26 /* Intializes random number generator */
nicovv44 4:0f34a6ad1f4c 27 srand((unsigned) time(&t));
nicovv44 4:0f34a6ad1f4c 28
bcostm 0:0e730157c767 29 BSP_LCD_SetFont(&Font24);
nicovv44 4:0f34a6ad1f4c 30
bcostm 0:0e730157c767 31 status = ts.Init(lcd.GetXSize(), lcd.GetYSize());
nicovv44 4:0f34a6ad1f4c 32 if (status != TS_OK) {
nicovv44 4:0f34a6ad1f4c 33 lcd.Clear(LCD_COLOR_RED);
nicovv44 4:0f34a6ad1f4c 34 lcd.SetBackColor(LCD_COLOR_RED);
nicovv44 4:0f34a6ad1f4c 35 lcd.SetTextColor(LCD_COLOR_WHITE);
nicovv44 4:0f34a6ad1f4c 36 lcd.DisplayStringAt(0, LINE(5), (uint8_t *)"TOUCHSCREEN INIT FAIL", CENTER_MODE);
nicovv44 4:0f34a6ad1f4c 37 } else {
nicovv44 4:0f34a6ad1f4c 38 lcd.Clear(LCD_COLOR_DARKGREEN);
nicovv44 4:0f34a6ad1f4c 39 lcd.SetBackColor(LCD_COLOR_DARKGREEN);
nicovv44 4:0f34a6ad1f4c 40 lcd.SetTextColor(LCD_COLOR_WHITE);
nicovv44 4:0f34a6ad1f4c 41 lcd.DisplayStringAt(0, LINE(5), (uint8_t *)"TOUCHSCREEN INIT OK", CENTER_MODE);
nicovv44 4:0f34a6ad1f4c 42 lcd.DisplayStringAt(0, LINE(6), (uint8_t *)"READY TO CHOSE YOUR LIFE", CENTER_MODE);
nicovv44 4:0f34a6ad1f4c 43 lcd.DisplayStringAt(0, LINE(8), (uint8_t *)"TOUCH TO DECIDE", CENTER_MODE);
bcostm 0:0e730157c767 44 }
bcostm 0:0e730157c767 45
nicovv44 4:0f34a6ad1f4c 46 lcd.SetBackColor(LCD_COLOR_LIGHTGRAY);
nicovv44 4:0f34a6ad1f4c 47 lcd.SetTextColor(LCD_COLOR_BLACK);
nicovv44 4:0f34a6ad1f4c 48
nicovv44 4:0f34a6ad1f4c 49 while(1) {
nicovv44 4:0f34a6ad1f4c 50 ts.GetState(&TS_State);
nicovv44 4:0f34a6ad1f4c 51 if (TS_State.touchDetected && fingerPress==0) {//finger lands
nicovv44 4:0f34a6ad1f4c 52 fingerPress = 1;
nicovv44 4:0f34a6ad1f4c 53 /* background */
nicovv44 4:0f34a6ad1f4c 54 lcd.Clear(LCD_COLOR_LIGHTGRAY);
nicovv44 4:0f34a6ad1f4c 55 wait(0.1);
nicovv44 4:0f34a6ad1f4c 56 /* decision counter */
nicovv44 4:0f34a6ad1f4c 57 sprintf((char*)text, "Decision#:%d", decisionCounter++);
nicovv44 4:0f34a6ad1f4c 58 lcd.DisplayStringAt(0, LINE(0), (uint8_t *)&text, LEFT_MODE);
nicovv44 4:0f34a6ad1f4c 59 /* decision of direction*/
nicovv44 4:0f34a6ad1f4c 60 direction = rand()%2;
nicovv44 4:0f34a6ad1f4c 61 switch(direction) {
nicovv44 4:0f34a6ad1f4c 62 case LEFT:
nicovv44 4:0f34a6ad1f4c 63 sprintf((char*)text, "LEFT");
nicovv44 4:0f34a6ad1f4c 64 //horizontal bar
nicovv44 4:0f34a6ad1f4c 65 lcd.FillRect(250,300,300,20);
nicovv44 4:0f34a6ad1f4c 66 //top diagonal
nicovv44 4:0f34a6ad1f4c 67 points[0].X=250;
nicovv44 4:0f34a6ad1f4c 68 points[0].Y=300;
nicovv44 4:0f34a6ad1f4c 69 points[1].X=250+80;
nicovv44 4:0f34a6ad1f4c 70 points[1].Y=300-70;
nicovv44 4:0f34a6ad1f4c 71 points[2].X=250+20+80;
nicovv44 4:0f34a6ad1f4c 72 points[2].Y=300-70;
nicovv44 4:0f34a6ad1f4c 73 points[3].X=250+20;
nicovv44 4:0f34a6ad1f4c 74 points[3].Y=300;
nicovv44 4:0f34a6ad1f4c 75 lcd.FillPolygon(points, 4);
nicovv44 4:0f34a6ad1f4c 76 //bottom diagonal
nicovv44 4:0f34a6ad1f4c 77 points[0].X=250;
nicovv44 4:0f34a6ad1f4c 78 points[0].Y=300+20;
nicovv44 4:0f34a6ad1f4c 79 points[1].X=250+80;
nicovv44 4:0f34a6ad1f4c 80 points[1].Y=300+70+20;
nicovv44 4:0f34a6ad1f4c 81 points[2].X=250+20+80;
nicovv44 4:0f34a6ad1f4c 82 points[2].Y=300+70+20;
nicovv44 4:0f34a6ad1f4c 83 points[3].X=250+20;
nicovv44 4:0f34a6ad1f4c 84 points[3].Y=300+20;
nicovv44 4:0f34a6ad1f4c 85 lcd.FillPolygon(points, 4);
nicovv44 4:0f34a6ad1f4c 86 break;
nicovv44 4:0f34a6ad1f4c 87 case RIGHT:
nicovv44 4:0f34a6ad1f4c 88 sprintf((char*)text, "RIGHT");
nicovv44 4:0f34a6ad1f4c 89 //horizontal bar
nicovv44 4:0f34a6ad1f4c 90 lcd.FillRect(250,300,300,20);
nicovv44 4:0f34a6ad1f4c 91 //top diagonal
nicovv44 4:0f34a6ad1f4c 92 points[0].X=250+300-20;
nicovv44 4:0f34a6ad1f4c 93 points[0].Y=300;
nicovv44 4:0f34a6ad1f4c 94 points[1].X=250+300-20-80;
nicovv44 4:0f34a6ad1f4c 95 points[1].Y=300-70;
nicovv44 4:0f34a6ad1f4c 96 points[2].X=250+300-80;
nicovv44 4:0f34a6ad1f4c 97 points[2].Y=300-70;
nicovv44 4:0f34a6ad1f4c 98 points[3].X=250+300;
nicovv44 4:0f34a6ad1f4c 99 points[3].Y=300;
nicovv44 4:0f34a6ad1f4c 100 lcd.FillPolygon(points, 4);
nicovv44 4:0f34a6ad1f4c 101 //bottom diagonal
nicovv44 4:0f34a6ad1f4c 102 points[0].X=250+300-20;
nicovv44 4:0f34a6ad1f4c 103 points[0].Y=300+20;
nicovv44 4:0f34a6ad1f4c 104 points[1].X=250+300-20-80;
nicovv44 4:0f34a6ad1f4c 105 points[1].Y=300+70+20;
nicovv44 4:0f34a6ad1f4c 106 points[2].X=250+300-80;
nicovv44 4:0f34a6ad1f4c 107 points[2].Y=300+70+20;
nicovv44 4:0f34a6ad1f4c 108 points[3].X=250+300;
nicovv44 4:0f34a6ad1f4c 109 points[3].Y=300+20;
nicovv44 4:0f34a6ad1f4c 110 lcd.FillPolygon(points, 4);
nicovv44 4:0f34a6ad1f4c 111 break;
nicovv44 4:0f34a6ad1f4c 112 }
nicovv44 4:0f34a6ad1f4c 113 //display text of direction
nicovv44 4:0f34a6ad1f4c 114 lcd.DisplayStringAt(0, LINE(6), (uint8_t *)&text, CENTER_MODE);
bcostm 0:0e730157c767 115 }
nicovv44 4:0f34a6ad1f4c 116 if(!TS_State.touchDetected && fingerPress==1) {//finger takes off
nicovv44 4:0f34a6ad1f4c 117 fingerPress = 0;
bcostm 0:0e730157c767 118 }
nicovv44 4:0f34a6ad1f4c 119 if(!TS_State.touchDetected) {//finger is flying
bcostm 0:0e730157c767 120 }
nicovv44 4:0f34a6ad1f4c 121 if(TS_State.touchDetected) {//finger is on the ground
nicovv44 4:0f34a6ad1f4c 122 }
bcostm 0:0e730157c767 123 }
bcostm 0:0e730157c767 124 }