FINAL CODE COMMENTED
Dependencies: Motor Servo22oct mbed
Fork of projecto0003030020 by
main.cpp
- Committer:
- KyleSchaff
- Date:
- 2014-11-02
- Revision:
- 6:29245562bba3
- Parent:
- 5:a7c0a09a7c58
File content as of revision 6:29245562bba3:
//Project X // Jordan Kangwijaya, Gabe Collins, Kyle Schaff #include "mbed.h" #include "Servo.h" #include "Motor.h" BusIn Switch(p16,p17,p18,p19); //declares switches BusOut LED(p5,p6,p7,p8,p11); //declares LEDs Motor m(p26,p29,p30); //declares motor Servo servo1(p21); //top .39 to 1.02 declares servos Servo servo2(p22); //bottom .38 to .93 float servopos; //variable will be used to control servo positions float motorspeed=.35; //variable will be used to control motorspeed int counter=0; int counter1=0; //counters will be used later to control LEDs int main() { while(1) { //so switches always work, and program is constantly checking on switches being on or off while (Switch==1) { //while switch 1 is on for(servopos=.40; servopos<=.60; servopos+=.03) { servo1=.7; //sets constant position for servo1 servo2=servopos; //sets servo2's position equal to the variable in the for loop, moving the servo from position 1 to position 2 motorspeed=0; //no motor speed for this level m.speed(motorspeed); counter=counter+1; //counter will count up by one each iteration counter1=counter%20; //counter 2 will count up until it reaches 20, then starts over if (counter1==17) { //every twentieth iteration, on the seventeenth, this happens LED=rand()%129; //sets LEDs to randomly light up } wait (.1); //low wait time for smooth motion } for(servopos=.60; servopos>=.40; servopos-=.03) { servo1=.7; //sets constant position for servo1 servo2=servopos; //sets servo2's position equal to the variable in the for loop, moving the servo from position 2 to position 1 motorspeed=0; //no motor speed for this level m.speed(motorspeed); counter=counter+1; //counter will count up by one each iteration counter1=counter%20; //counter 2 will count up until it reaches 20, then starts over if (counter1==17) { //every twentieth iteration, on the seventeenth, this happens LED=rand()%129; //sets LEDs to randomly light up } wait (.1); //low wait time for smooth motion } } while(Switch==2) { for(servopos=.40; servopos<=.60; servopos+=.03) { servo1=servopos+.2; //sets servo1's position equal to the variable in the for loop, moving the servo from position 1 to position 2 servo2=.5; motorspeed=0; //no motor speed for this level m.speed(motorspeed); counter=counter+1; //counter will count up by one each iteration counter1=counter%20; //counter 2 will count up until it reaches 20, then starts over if (counter1==17) { //every twentieth iteration, on the seventeenth, this happens LED=rand()%129; //sets LEDs to randomly light up } wait (.03); //low wait time for smooth motion } for(servopos=.60; servopos>=.40; servopos-=.03) { servo1=servopos+.2; //sets servo1's position equal to the variable in the for loop, moving the servo from position 2 to position 1 servo2=.5; motorspeed=0; //no motor speed for this level m.speed(motorspeed); counter=counter+1; //counter will count up by one each iteration counter1=counter%20; //counter 2 will count up until it reaches 20, then starts over if (counter1==17) { //every twentieth iteration, on the seventeenth, this happens LED=rand()%129; //sets LEDs to randomly light up } wait (.03); //low wait time for smooth motion } } while(Switch==4) { for(servopos=.40; servopos<=.60; servopos+=.03) { servo1=servopos+.2; //sets servo1's position equal to the variable in the for loop, moving the servo from position 1 to position 2 servo2=servopos; //sets servo2's position equal to the variable in the for loop, moving the servo from position 1 to position 2 counter=counter+1; //counter will count up by one each iteration counter1=counter%20; //counter 2 will count up until it reaches 20, then starts over if (counter1==17) { //every twentieth iteration, on the seventeenth, this happens LED=rand()%129; //sets LEDs to randomly light up } wait (.02); //low wait time for smooth motion } for(servopos=.60; servopos>=.40; servopos-=.03) { servo1=servopos+.2; //sets servo1's position equal to the variable in the for loop, moving the servo from position 2 to position 1 servo2=servopos; //sets servo2's position equal to the variable in the for loop, moving the servo from position 2 to position 1 counter=counter+1; //counter will count up by one each iteration counter1=counter%20; //counter 2 will count up until it reaches 20, then starts over if (counter1==17) { //every twentieth iteration, on the seventeenth, this happens LED=rand()%129; //sets LEDs to randomly light up } wait (.02); //low wait time for smooth motion } } while(Switch==8) { motorspeed=.35; m.speed(motorspeed); for(servopos=.40; servopos<=.60; servopos+=.03) { servo1=servopos+.2; //sets servo1's position equal to the variable in the for loop, moving the servo from position 1 to position 2 servo2=servopos; //sets servo2's position equal to the variable in the for loop, moving the servo from position 1 to position 2 m.speed(motorspeed); counter=counter+1; //counter will count up by one each iteration counter1=counter%20; //counter 2 will count up until it reaches 20, then starts over if (counter1==17) { //every twentieth iteration, on the seventeenth, this happens LED=rand()%129; //sets LEDs to randomly light up } wait (.025); //low wait time for smooth motion } for(servopos=.60; servopos>=.40; servopos-=.03) { servo1=servopos+.2; //sets servo2's position equal to the variable in the for loop, moving the servo from position 2 to position 1 servo2=servopos; //sets servo2's position equal to the variable in the for loop, moving the servo from position 2 to position 1 m.speed(motorspeed); counter=counter+1; //counter will count up by one each iteration counter1=counter%20; //counter 2 will count up until it reaches 20, then starts over if (counter1==17) { //every twentieth iteration, on the seventeenth, this happens LED=rand()%129; //sets LEDs to randomly light up } wait (.025); //low wait time for smooth motion } } while(Switch==0) { //neutral position when no switches are on servo1=.7; //neutral position when no switches are on servo2=.5; //neutral position when no switches are on motorspeed=0; //neutral motor speed when no switches are on m.speed(motorspeed); } } }