heres the code
Dependencies: Motor Servo mbed
Diff: main.cpp
- Revision:
- 6:d58256361419
- Parent:
- 4:3447c3fa5719
- Child:
- 7:8881672744fd
--- a/main.cpp Tue Oct 09 15:36:01 2018 +0000 +++ b/main.cpp Mon Oct 22 14:45:12 2018 +0000 @@ -1,35 +1,48 @@ -#include "mbed.h" + #include "mbed.h" #include "stdio.h" #include "Motor.h" #include "Servo.h" #include "time.h" -time_t t; - +Motor knife(p26, p30, p29); Servo finish(p22); Servo start(p21); +DigitalOut led[4]={LED1, LED2, LED3, LED4}; int i, j; -float x; - int curTime = time(&t); +int x; - + int main() { start.calibrate(0.0009, 90.0); finish.calibrate(0.0009, 90.0); - finish = 0.5; //set finish gate to halfway point + + start = 0.25; //lowers start gate + wait (1.0); //gives time for crab to get down track - for (i=0; i<1; i++) { - start = 1.0; //lowers start gate - - } - wait (3.0); //gives time for crab to get down track x = (rand()%9)+1; + printf("%d", x); - if (x <= 7) { + start = 0.0; //set initial start gate position + + + if (x >= 7) { finish = 1.0; //gate has a 70% chance to go one way + for (i=0; i<5; i++) { + led[i] = 1; + wait (0.15); + led[i]=0; } + } else { //30% chance the gate will go the other way - finish = 0.0; } + finish = 0.0; + knife.speed (0.5); + wait (.5); + knife.speed (-0.5); + wait (.5); + knife.speed(0); + } - start = 0.0; //set initial start gate position + finish = 0.5; //set finish gate to halfway point + + } \ No newline at end of file