cool
Dependencies: Motor Servo mbed
Revision 1:50490d67ac7e, committed 2014-10-22
- Comitter:
- m170984
- Date:
- Wed Oct 22 01:20:11 2014 +0000
- Parent:
- 0:af31e48dd848
- Commit message:
- commit
Changed in this revision
Servo.lib | Show annotated file Show diff for this revision Revisions of this file |
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r af31e48dd848 -r 50490d67ac7e Servo.lib --- a/Servo.lib Fri Oct 03 19:00:30 2014 +0000 +++ b/Servo.lib Wed Oct 22 01:20:11 2014 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/simon/code/Servo/#36b69a7ced07 +http://developer.mbed.org/teams/The-Best-Team-Ever/code/Servo/#2b950e527256
diff -r af31e48dd848 -r 50490d67ac7e main.cpp --- a/main.cpp Fri Oct 03 19:00:30 2014 +0000 +++ b/main.cpp Wed Oct 22 01:20:11 2014 +0000 @@ -2,23 +2,122 @@ #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.5); + wait(0.01); } void closegate() //function to close the gate { myservo1 = 0; - wait(0.5); + wait(0.01); } int main() { - opengate(); - closegate(); + 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; + } + } }