Rube Goldberg machine

Dependencies:   4DGL-uLCD-SE mbed PinDetect

main.cpp

Committer:
nhardy6
Date:
2016-09-25
Revision:
1:5315c3a587a0
Parent:
0:26331a8bcec1
Child:
2:2bb8f06b7924

File content as of revision 1:5315c3a587a0:

#include "mbed.h"
#include "PinDetect.h"
#include "uLCD_4DGL.h"

Timer t;    //timer to generate number

PinDetect begin(p5);  //start of it all
volatile bool stop = 0;
int num;

DigitalOut d1(p21); //display number in binary
DigitalOut d2(p22);
DigitalOut d3(p23);

uLCD_4DGL uLCD(p9,p10,p11); // serial tx, serial rx, reset pin;

void start()    //make random numbers and fast lights until flip value
{
    while(!stop)
    {
        d1 = !d1;
        d2 = !d2;
        d3 = !d3;
        num = t.read_us()%8;
        wait(0.2);
    }
}

void stopper()     //flip the value
{
    stop = 1;
}

void lights()
{
    if (num > 3)
    {
        d1 = 1;
    }
    if (num == 2 || num == 3 || num == 6 || num == 7)
    {
        d2 = 1;
    }
    if ((num % 2) == 1)
    {
        d3 = 1;
    }
}

int main()
{
    t.start();              //start timer
    uLCD.cls();             //prepare screen
    uLCD.baudrate(3000000);
    wait(.1);               //wait just in case
    uLCD.printf("pls1");    //debug
    uLCD.printf("pls2");
    begin.mode(PullUp);     //attach interrupt
    wait(.001);             //setup delay
    begin.attach_deasserted(&stopper);
    uLCD.printf("starting \n");
    start();                //begin the choosing
    uLCD.printf("got the number \n");
    lights();               //light lights according to generated number
    uLCD.printf("did the lights \n");
}