cool
Dependencies: Motor Servo mbed
main.cpp
- Committer:
- m170984
- Date:
- 2014-10-22
- Revision:
- 1:50490d67ac7e
- Parent:
- 0:af31e48dd848
File content as of revision 1:50490d67ac7e:
#include "mbed.h" #include "Motor.h" #include "Servo.h" // I left my code open and unguarded!! // I'm a tree! //Digital I/O Motor m(p26, p29, p30); // pins to use for pwm, fwd, rev Servo myservo1(p21); //declare servos Servo myservo2(p22); DigitalOut led[5] = {p5,p6,p7,p8,p11}; //array for leds DigitalIn num (p16); // set variable num to read from the board switches DigitalIn num2 (p17); DigitalIn num3 (p18); int fl =2; void flash() { if (led[fl] ==0) { led[fl] =1; wait(0.1); } else { led[fl] = 0; wait(0.1); } if (fl < 4) { fl++; } else { fl=2; } } void opengate() // function to open the gate { myservo1 = 1; wait(0.01); } void closegate() //function to close the gate { myservo1 = 0; wait(0.01); } int main() { float wiggle =0; myservo2=wiggle; int tofro = 0; float i=0.0; //speed var while(1)// THE Loop { flash(); if(num == 0) { led[0] = 0; closegate(); } if(num == 1) { led[0] = 1; opengate(); } if(num2 == 1) { led[1] = 1; if(i<0.2) { i=i+0.1; m.speed(i); wait(0.5); } } if(num2 == 0) { led[1] = 0; if(i>0) { i=i-0.08; m.speed(i); wait(0.5); } } if (num3 == 1) { if (tofro==0) { wiggle = wiggle + 0.01; myservo2 = wiggle; wait(0.01); if(wiggle >= 0.1) { tofro=1; } } if (tofro==1) { wiggle = wiggle - 0.01; myservo2 = wiggle; wait(0.01); if (wiggle <= 0) { tofro =0; } } } if(num3==0) { wiggle =0; myservo2 = wiggle; wait(0.01); tofro=0; } } }