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:
Wed May 29 01:22:52 2019 +0000
Branch:
MasterchiefOffice
Revision:
10:0de9ce9dd5b8
Parent:
9:5c2f112a2b0b
Change text

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 5:ef44b84a149f 19 uint16_t x, y;
nicovv44 5:ef44b84a149f 20 uint8_t direction, decisionCounter, countdown;
nicovv44 5:ef44b84a149f 21 uint8_t firstDecision;
nicovv44 4:0f34a6ad1f4c 22 uint8_t text[30] = "";
bcostm 0:0e730157c767 23 uint8_t status;
nicovv44 5:ef44b84a149f 24 uint8_t fingerPress;
nicovv44 4:0f34a6ad1f4c 25 time_t t;
nicovv44 4:0f34a6ad1f4c 26 Point points[4];
nicovv44 4:0f34a6ad1f4c 27
nicovv44 4:0f34a6ad1f4c 28 /* Intializes random number generator */
nicovv44 4:0f34a6ad1f4c 29 srand((unsigned) time(&t));
nicovv44 4:0f34a6ad1f4c 30
bcostm 0:0e730157c767 31 BSP_LCD_SetFont(&Font24);
nicovv44 5:ef44b84a149f 32
nicovv44 5:ef44b84a149f 33 status = ts.Init(lcd.GetXSize(), lcd.GetYSize());
nicovv44 4:0f34a6ad1f4c 34
nicovv44 5:ef44b84a149f 35 home:
nicovv44 5:ef44b84a149f 36 decisionCounter = 1;
nicovv44 5:ef44b84a149f 37 firstDecision = 1;
nicovv44 5:ef44b84a149f 38 fingerPress = 0;
nicovv44 4:0f34a6ad1f4c 39 if (status != TS_OK) {
nicovv44 4:0f34a6ad1f4c 40 lcd.Clear(LCD_COLOR_RED);
nicovv44 5:ef44b84a149f 41 wait(0.1);//apparently we have to wait a bit after Clear
nicovv44 4:0f34a6ad1f4c 42 lcd.SetBackColor(LCD_COLOR_RED);
nicovv44 4:0f34a6ad1f4c 43 lcd.SetTextColor(LCD_COLOR_WHITE);
nicovv44 4:0f34a6ad1f4c 44 lcd.DisplayStringAt(0, LINE(5), (uint8_t *)"TOUCHSCREEN INIT FAIL", CENTER_MODE);
nicovv44 5:ef44b84a149f 45 goto end;
nicovv44 4:0f34a6ad1f4c 46 } else {
nicovv44 4:0f34a6ad1f4c 47 lcd.Clear(LCD_COLOR_DARKGREEN);
nicovv44 5:ef44b84a149f 48 wait(0.1);//apparently we have to wait a bit after Clear
nicovv44 4:0f34a6ad1f4c 49 lcd.SetBackColor(LCD_COLOR_DARKGREEN);
nicovv44 4:0f34a6ad1f4c 50 lcd.SetTextColor(LCD_COLOR_WHITE);
nicovv44 5:ef44b84a149f 51 //lcd.DisplayStringAt(0, LINE(5), (uint8_t *)"TOUCHSCREEN INIT OK", CENTER_MODE);
nicovv44 4:0f34a6ad1f4c 52 lcd.DisplayStringAt(0, LINE(6), (uint8_t *)"READY TO CHOSE YOUR LIFE", CENTER_MODE);
nicovv44 4:0f34a6ad1f4c 53 lcd.DisplayStringAt(0, LINE(8), (uint8_t *)"TOUCH TO DECIDE", CENTER_MODE);
bcostm 0:0e730157c767 54 }
bcostm 0:0e730157c767 55
nicovv44 4:0f34a6ad1f4c 56 lcd.SetBackColor(LCD_COLOR_LIGHTGRAY);
nicovv44 4:0f34a6ad1f4c 57 lcd.SetTextColor(LCD_COLOR_BLACK);
nicovv44 4:0f34a6ad1f4c 58
nicovv44 4:0f34a6ad1f4c 59 while(1) {
nicovv44 4:0f34a6ad1f4c 60 ts.GetState(&TS_State);
nicovv44 4:0f34a6ad1f4c 61 if (TS_State.touchDetected && fingerPress==0) {//finger lands
nicovv44 4:0f34a6ad1f4c 62 fingerPress = 1;
nicovv44 5:ef44b84a149f 63 /* get landing poosition */
nicovv44 5:ef44b84a149f 64 x = TS_State.touchX[0];
nicovv44 5:ef44b84a149f 65 y = TS_State.touchY[0];
nicovv44 5:ef44b84a149f 66 /* countdown */
nicovv44 5:ef44b84a149f 67 if(firstDecision){
nicovv44 5:ef44b84a149f 68 firstDecision = 0;
nicovv44 5:ef44b84a149f 69 lcd.Clear(LCD_COLOR_LIGHTGRAY);
nicovv44 5:ef44b84a149f 70 wait(0.1);//apparently we have to wait a bit after Clear
nicovv44 5:ef44b84a149f 71 for(countdown=10 ; countdown>0 ; countdown--){
nicovv44 5:ef44b84a149f 72 lcd.ClearStringLine(10);
nicovv44 5:ef44b84a149f 73 sprintf((char*)text, "Downloading cosmos energy...");
nicovv44 5:ef44b84a149f 74 lcd.DisplayStringAt(0, LINE(6), (uint8_t *)&text, CENTER_MODE);
nicovv44 5:ef44b84a149f 75 sprintf((char*)text, "%d", countdown);
nicovv44 5:ef44b84a149f 76 lcd.DisplayStringAt(0, LINE(10), (uint8_t *)&text, CENTER_MODE);
nicovv44 5:ef44b84a149f 77 wait(1.0);
nicovv44 5:ef44b84a149f 78 }
nicovv44 5:ef44b84a149f 79 }
nicovv44 5:ef44b84a149f 80 else{//finger lands, not the first decision
nicovv44 5:ef44b84a149f 81 if(x>lcd.GetXSize()-100 && y<100) goto home;
nicovv44 5:ef44b84a149f 82 }
nicovv44 4:0f34a6ad1f4c 83 lcd.Clear(LCD_COLOR_LIGHTGRAY);
nicovv44 5:ef44b84a149f 84 wait(0.1);//apparently we have to wait a bit after Clear
nicovv44 5:ef44b84a149f 85
nicovv44 5:ef44b84a149f 86 /* display return home button */
nicovv44 5:ef44b84a149f 87 lcd.SetTextColor(LCD_COLOR_DARKGREEN);
nicovv44 5:ef44b84a149f 88 lcd.FillRect(lcd.GetXSize()-100,0,100,100);
nicovv44 5:ef44b84a149f 89 lcd.SetBackColor(LCD_COLOR_DARKGREEN);
nicovv44 5:ef44b84a149f 90 lcd.SetTextColor(LCD_COLOR_WHITE);
nicovv44 5:ef44b84a149f 91 wait(0.01);
nicovv44 5:ef44b84a149f 92 sprintf((char*)text, "HOME");
nicovv44 5:ef44b84a149f 93 lcd.DisplayStringAt(10, LINE(1)+10, (uint8_t *)&text, RIGHT_MODE);
nicovv44 5:ef44b84a149f 94
nicovv44 5:ef44b84a149f 95 /* other colors */
nicovv44 5:ef44b84a149f 96 lcd.SetBackColor(LCD_COLOR_LIGHTGRAY);
nicovv44 5:ef44b84a149f 97 lcd.SetTextColor(LCD_COLOR_BLACK);
nicovv44 5:ef44b84a149f 98
nicovv44 4:0f34a6ad1f4c 99 /* decision counter */
nicovv44 4:0f34a6ad1f4c 100 sprintf((char*)text, "Decision#:%d", decisionCounter++);
nicovv44 4:0f34a6ad1f4c 101 lcd.DisplayStringAt(0, LINE(0), (uint8_t *)&text, LEFT_MODE);
nicovv44 5:ef44b84a149f 102
nicovv44 4:0f34a6ad1f4c 103 /* decision of direction*/
nicovv44 4:0f34a6ad1f4c 104 direction = rand()%2;
nicovv44 4:0f34a6ad1f4c 105 switch(direction) {
nicovv44 4:0f34a6ad1f4c 106 case LEFT:
nicovv44 10:0de9ce9dd5b8 107 sprintf((char*)text, "Masterchief");
nicovv44 9:5c2f112a2b0b 108 /*
nicovv44 4:0f34a6ad1f4c 109 //horizontal bar
nicovv44 4:0f34a6ad1f4c 110 lcd.FillRect(250,300,300,20);
nicovv44 4:0f34a6ad1f4c 111 //top diagonal
nicovv44 4:0f34a6ad1f4c 112 points[0].X=250;
nicovv44 4:0f34a6ad1f4c 113 points[0].Y=300;
nicovv44 4:0f34a6ad1f4c 114 points[1].X=250+80;
nicovv44 4:0f34a6ad1f4c 115 points[1].Y=300-70;
nicovv44 4:0f34a6ad1f4c 116 points[2].X=250+20+80;
nicovv44 4:0f34a6ad1f4c 117 points[2].Y=300-70;
nicovv44 4:0f34a6ad1f4c 118 points[3].X=250+20;
nicovv44 4:0f34a6ad1f4c 119 points[3].Y=300;
nicovv44 4:0f34a6ad1f4c 120 lcd.FillPolygon(points, 4);
nicovv44 4:0f34a6ad1f4c 121 //bottom diagonal
nicovv44 4:0f34a6ad1f4c 122 points[0].X=250;
nicovv44 4:0f34a6ad1f4c 123 points[0].Y=300+20;
nicovv44 4:0f34a6ad1f4c 124 points[1].X=250+80;
nicovv44 4:0f34a6ad1f4c 125 points[1].Y=300+70+20;
nicovv44 4:0f34a6ad1f4c 126 points[2].X=250+20+80;
nicovv44 4:0f34a6ad1f4c 127 points[2].Y=300+70+20;
nicovv44 4:0f34a6ad1f4c 128 points[3].X=250+20;
nicovv44 4:0f34a6ad1f4c 129 points[3].Y=300+20;
nicovv44 4:0f34a6ad1f4c 130 lcd.FillPolygon(points, 4);
nicovv44 9:5c2f112a2b0b 131 */
nicovv44 4:0f34a6ad1f4c 132 break;
nicovv44 4:0f34a6ad1f4c 133 case RIGHT:
nicovv44 10:0de9ce9dd5b8 134 sprintf((char*)text, "The Office");
nicovv44 9:5c2f112a2b0b 135 /*
nicovv44 4:0f34a6ad1f4c 136 //horizontal bar
nicovv44 4:0f34a6ad1f4c 137 lcd.FillRect(250,300,300,20);
nicovv44 4:0f34a6ad1f4c 138 //top diagonal
nicovv44 4:0f34a6ad1f4c 139 points[0].X=250+300-20;
nicovv44 4:0f34a6ad1f4c 140 points[0].Y=300;
nicovv44 4:0f34a6ad1f4c 141 points[1].X=250+300-20-80;
nicovv44 4:0f34a6ad1f4c 142 points[1].Y=300-70;
nicovv44 4:0f34a6ad1f4c 143 points[2].X=250+300-80;
nicovv44 4:0f34a6ad1f4c 144 points[2].Y=300-70;
nicovv44 4:0f34a6ad1f4c 145 points[3].X=250+300;
nicovv44 4:0f34a6ad1f4c 146 points[3].Y=300;
nicovv44 4:0f34a6ad1f4c 147 lcd.FillPolygon(points, 4);
nicovv44 4:0f34a6ad1f4c 148 //bottom diagonal
nicovv44 4:0f34a6ad1f4c 149 points[0].X=250+300-20;
nicovv44 4:0f34a6ad1f4c 150 points[0].Y=300+20;
nicovv44 4:0f34a6ad1f4c 151 points[1].X=250+300-20-80;
nicovv44 4:0f34a6ad1f4c 152 points[1].Y=300+70+20;
nicovv44 4:0f34a6ad1f4c 153 points[2].X=250+300-80;
nicovv44 4:0f34a6ad1f4c 154 points[2].Y=300+70+20;
nicovv44 4:0f34a6ad1f4c 155 points[3].X=250+300;
nicovv44 4:0f34a6ad1f4c 156 points[3].Y=300+20;
nicovv44 4:0f34a6ad1f4c 157 lcd.FillPolygon(points, 4);
nicovv44 9:5c2f112a2b0b 158 */
nicovv44 4:0f34a6ad1f4c 159 break;
nicovv44 4:0f34a6ad1f4c 160 }
nicovv44 4:0f34a6ad1f4c 161 //display text of direction
nicovv44 4:0f34a6ad1f4c 162 lcd.DisplayStringAt(0, LINE(6), (uint8_t *)&text, CENTER_MODE);
bcostm 0:0e730157c767 163 }
nicovv44 4:0f34a6ad1f4c 164 if(!TS_State.touchDetected && fingerPress==1) {//finger takes off
nicovv44 4:0f34a6ad1f4c 165 fingerPress = 0;
bcostm 0:0e730157c767 166 }
nicovv44 4:0f34a6ad1f4c 167 if(!TS_State.touchDetected) {//finger is flying
bcostm 0:0e730157c767 168 }
nicovv44 4:0f34a6ad1f4c 169 if(TS_State.touchDetected) {//finger is on the ground
nicovv44 4:0f34a6ad1f4c 170 }
bcostm 0:0e730157c767 171 }
nicovv44 5:ef44b84a149f 172 end:
nicovv44 5:ef44b84a149f 173 {}
bcostm 0:0e730157c767 174 }