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:
bcostm
Date:
Fri Dec 18 09:06:55 2015 +0000
Revision:
0:0e730157c767
Child:
4:0f34a6ad1f4c
Initial version

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"
bcostm 0:0e730157c767 4
bcostm 0:0e730157c767 5 LCD_DISCO_F469NI lcd;
bcostm 0:0e730157c767 6 TS_DISCO_F469NI ts;
bcostm 0:0e730157c767 7
bcostm 0:0e730157c767 8 int main()
bcostm 0:0e730157c767 9 {
bcostm 0:0e730157c767 10 TS_StateTypeDef TS_State;
bcostm 0:0e730157c767 11 uint16_t x, y;
bcostm 0:0e730157c767 12 uint8_t text[30];
bcostm 0:0e730157c767 13 uint8_t status;
bcostm 0:0e730157c767 14 uint8_t idx;
bcostm 0:0e730157c767 15 uint8_t cleared = 0;
bcostm 0:0e730157c767 16 uint8_t prev_nb_touches = 0;
bcostm 0:0e730157c767 17
bcostm 0:0e730157c767 18 BSP_LCD_SetFont(&Font24);
bcostm 0:0e730157c767 19
bcostm 0:0e730157c767 20 lcd.DisplayStringAt(0, LINE(5), (uint8_t *)"TOUCHSCREEN DEMO", CENTER_MODE);
bcostm 0:0e730157c767 21 wait(1);
bcostm 0:0e730157c767 22
bcostm 0:0e730157c767 23 status = ts.Init(lcd.GetXSize(), lcd.GetYSize());
bcostm 0:0e730157c767 24 if (status != TS_OK)
bcostm 0:0e730157c767 25 {
bcostm 0:0e730157c767 26 lcd.Clear(LCD_COLOR_RED);
bcostm 0:0e730157c767 27 lcd.SetBackColor(LCD_COLOR_RED);
bcostm 0:0e730157c767 28 lcd.SetTextColor(LCD_COLOR_WHITE);
bcostm 0:0e730157c767 29 lcd.DisplayStringAt(0, LINE(5), (uint8_t *)"TOUCHSCREEN INIT FAIL", CENTER_MODE);
bcostm 0:0e730157c767 30 }
bcostm 0:0e730157c767 31 else
bcostm 0:0e730157c767 32 {
bcostm 0:0e730157c767 33 lcd.Clear(LCD_COLOR_GREEN);
bcostm 0:0e730157c767 34 lcd.SetBackColor(LCD_COLOR_GREEN);
bcostm 0:0e730157c767 35 lcd.SetTextColor(LCD_COLOR_WHITE);
bcostm 0:0e730157c767 36 lcd.DisplayStringAt(0, LINE(5), (uint8_t *)"TOUCHSCREEN INIT OK", CENTER_MODE);
bcostm 0:0e730157c767 37 }
bcostm 0:0e730157c767 38
bcostm 0:0e730157c767 39 wait(1);
bcostm 0:0e730157c767 40 lcd.SetBackColor(LCD_COLOR_BLUE);
bcostm 0:0e730157c767 41 lcd.SetTextColor(LCD_COLOR_WHITE);
bcostm 0:0e730157c767 42
bcostm 0:0e730157c767 43 while(1)
bcostm 0:0e730157c767 44 {
bcostm 0:0e730157c767 45
bcostm 0:0e730157c767 46 ts.GetState(&TS_State);
bcostm 0:0e730157c767 47 if (TS_State.touchDetected)
bcostm 0:0e730157c767 48 {
bcostm 0:0e730157c767 49 // Clear lines corresponding to old touches coordinates
bcostm 0:0e730157c767 50 if (TS_State.touchDetected < prev_nb_touches)
bcostm 0:0e730157c767 51 {
bcostm 0:0e730157c767 52 for (idx = (TS_State.touchDetected + 1); idx <= 5; idx++)
bcostm 0:0e730157c767 53 {
bcostm 0:0e730157c767 54 lcd.ClearStringLine(idx);
bcostm 0:0e730157c767 55 }
bcostm 0:0e730157c767 56 }
bcostm 0:0e730157c767 57 prev_nb_touches = TS_State.touchDetected;
bcostm 0:0e730157c767 58
bcostm 0:0e730157c767 59 cleared = 0;
bcostm 0:0e730157c767 60
bcostm 0:0e730157c767 61 sprintf((char*)text, "Touches: %d", TS_State.touchDetected);
bcostm 0:0e730157c767 62 lcd.DisplayStringAt(0, LINE(0), (uint8_t *)&text, LEFT_MODE);
bcostm 0:0e730157c767 63
bcostm 0:0e730157c767 64 for (idx = 0; idx < TS_State.touchDetected; idx++)
bcostm 0:0e730157c767 65 {
bcostm 0:0e730157c767 66 x = TS_State.touchX[idx];
bcostm 0:0e730157c767 67 y = TS_State.touchY[idx];
bcostm 0:0e730157c767 68 sprintf((char*)text, "Touch %d: x=%d y=%d ", idx+1, x, y);
bcostm 0:0e730157c767 69 lcd.DisplayStringAt(0, LINE(idx+1), (uint8_t *)&text, LEFT_MODE);
bcostm 0:0e730157c767 70 lcd.FillCircle(TS_State.touchX[idx], TS_State.touchY[idx], 20);
bcostm 0:0e730157c767 71 }
bcostm 0:0e730157c767 72 }
bcostm 0:0e730157c767 73 else
bcostm 0:0e730157c767 74 {
bcostm 0:0e730157c767 75 if (!cleared)
bcostm 0:0e730157c767 76 {
bcostm 0:0e730157c767 77 lcd.Clear(LCD_COLOR_BLUE);
bcostm 0:0e730157c767 78 sprintf((char*)text, "Touches: 0");
bcostm 0:0e730157c767 79 lcd.DisplayStringAt(0, LINE(0), (uint8_t *)&text, LEFT_MODE);
bcostm 0:0e730157c767 80 cleared = 1;
bcostm 0:0e730157c767 81 }
bcostm 0:0e730157c767 82 }
bcostm 0:0e730157c767 83 }
bcostm 0:0e730157c767 84 }