Dependencies: mbed
main.cpp
- Committer:
- jaredwil
- Date:
- 2015-02-08
- Revision:
- 3:f652c4b6b709
- Parent:
- 2:bfe32024e001
File content as of revision 3:f652c4b6b709:
#include "mbed.h" #include "math.h" //Establish Serial Interface Serial pc(USBTX, USBRX); //Define System Inputs and Ouputs DigitalOut myled1(LED1); DigitalOut myled2(LED2); DigitalOut myled3(LED3); DigitalOut myled4(LED4); Timer timer; int main() { //Initialze randomness srand(time(NULL)); //Define the random sequence of leds length 10 (Either 0, 1, 2, 3) int a = (rand()%4); int b = (rand()%4); int c = (rand()%4); int d = (rand()%4); int e = (rand()%4); int f = (rand()%4); int g = (rand()%4); int h = (rand()%4); int i = (rand()%4); int j = (rand()%4); int pattern[10] = {a,b,c,d,e,f,g,h,i,j}; //Debug purposes pc.printf("A: %f, %f, %f",a,b,c); while(1) { timer.start(); //start timer //ensure only loop once (18 seconds) while(timer.read() < 18){ //Loop through random patter defined at startup for(int i = 0; i < 10; i+= 1){ switch(pattern[i]) { case 0: myled1 = 1; wait(1.8); myled1 = 0; break; case 1: myled2 = 1; wait(1.8); myled2 = 0; break; case 2: myled3 = 1; wait(1.8); myled3 = 0; break; case 3: myled4 = 1; wait(1.8); myled4 = 0; break; } } } timer.reset(); //reset timer } }