heres the code
Dependencies: Motor Servo mbed
main.cpp
- Committer:
- JackTamas
- Date:
- 2018-10-22
- Revision:
- 7:8881672744fd
- Parent:
- 6:d58256361419
File content as of revision 7:8881672744fd:
#include "mbed.h" #include "stdio.h" #include "Motor.h" #include "Servo.h" #include "time.h" Motor knife(p26, p30, p29); Servo finish(p22); Servo start(p21); DigitalOut led[4]={LED1, LED2, LED3, LED4}; int i, j; int x; int main() { start.calibrate(0.0009, 90.0); finish.calibrate(0.0009, 90.0); start = 0.25; //lowers start gate wait (1.0); //gives time for crab to get down track x = (rand()%9)+1; printf("%d", x); 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; knife.speed (0.5); wait (.5); knife.speed (-0.5); wait (.5); knife.speed(0); } finish = 0.5; //set finish gate to halfway point }