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.

main.cpp

Committer:
nicovv44
Date:
2019-05-16
Revision:
4:0f34a6ad1f4c
Parent:
0:0e730157c767
Child:
5:ef44b84a149f

File content as of revision 4:0f34a6ad1f4c:

#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;
    uint8_t direction, decisionCounter=1;
    uint8_t text[30] = "";
    uint8_t status;
    uint8_t fingerPress = 0;
    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());
    if (status != TS_OK) {
        lcd.Clear(LCD_COLOR_RED);
        lcd.SetBackColor(LCD_COLOR_RED);
        lcd.SetTextColor(LCD_COLOR_WHITE);
        lcd.DisplayStringAt(0, LINE(5), (uint8_t *)"TOUCHSCREEN INIT FAIL", CENTER_MODE);
    } else {
        lcd.Clear(LCD_COLOR_DARKGREEN);
        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;
            /* background */
            lcd.Clear(LCD_COLOR_LIGHTGRAY);
            wait(0.1);
            /* 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
        }
    }
}