Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: Motor Servo22oct mbed
Fork of projecto0003030020 by
Revision 6:29245562bba3, committed 2014-11-02
- Comitter:
- KyleSchaff
- Date:
- Sun Nov 02 20:06:01 2014 +0000
- Parent:
- 5:a7c0a09a7c58
- Commit message:
- FINAL CODE COMMENTED;
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r a7c0a09a7c58 -r 29245562bba3 main.cpp
--- a/main.cpp Thu Oct 23 17:49:36 2014 +0000
+++ b/main.cpp Sun Nov 02 20:06:01 2014 +0000
@@ -5,100 +5,100 @@
#include "Servo.h"
#include "Motor.h"
-BusIn Switch(p16,p17,p18,p19);
-BusOut LED(p5,p6,p7,p8,p11);
+BusIn Switch(p16,p17,p18,p19); //declares switches
+BusOut LED(p5,p6,p7,p8,p11); //declares LEDs
-Motor m(p26,p29,p30);
-Servo servo1(p21); //top .39 to 1.02
+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;
-float motorspeed=.35;
-int counter=0;
-int counter1=0;
+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) {
+ while(1) { //so switches always work, and program is constantly checking on switches being on or off
- while (Switch==1) {
+ while (Switch==1) { //while switch 1 is on
for(servopos=.40; servopos<=.60; servopos+=.03) {
- servo1=.7;
- servo2=servopos;
- motorspeed=0;
+ 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;
- counter1=counter%20;
- if (counter1==17) {
- LED=rand()%129;
+ 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);
+ wait (.1); //low wait time for smooth motion
}
for(servopos=.60; servopos>=.40; servopos-=.03) {
- servo1=.7;
- servo2=servopos;
- motorspeed=0;
+ 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;
- counter1=counter%20;
- if (counter1==17) {
- LED=rand()%129;
+ 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);
+ wait (.1); //low wait time for smooth motion
}
- }//Swartzwelder swartzwe.usna.edu
+ }
while(Switch==2) {
for(servopos=.40; servopos<=.60; servopos+=.03) {
- servo1=servopos+.2;
+ 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;
+ motorspeed=0; //no motor speed for this level
m.speed(motorspeed);
- counter=counter+1;
- counter1=counter%20;
- if (counter1==17) {
- LED=rand()%129;
+ 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);
+ wait (.03); //low wait time for smooth motion
}
for(servopos=.60; servopos>=.40; servopos-=.03) {
- servo1=servopos+.2;
+ 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;
+ motorspeed=0; //no motor speed for this level
m.speed(motorspeed);
- counter=counter+1;
- counter1=counter%20;
- if (counter1==17) {
- LED=rand()%129;
+ 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);
+ wait (.03); //low wait time for smooth motion
}
}
while(Switch==4) {
for(servopos=.40; servopos<=.60; servopos+=.03) {
- servo1=servopos+.2;
- servo2=servopos;
- counter=counter+1;
- counter1=counter%20;
- if (counter1==17) {
- LED=rand()%129;
+ 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);
+ wait (.02); //low wait time for smooth motion
}
for(servopos=.60; servopos>=.40; servopos-=.03) {
- servo1=servopos+.2;
- servo2=servopos;
- counter=counter+1;
- counter1=counter%20;
- if (counter1==17) {
- LED=rand()%129;
+ 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);
+ wait (.02); //low wait time for smooth motion
}
}
@@ -106,33 +106,33 @@
motorspeed=.35;
m.speed(motorspeed);
for(servopos=.40; servopos<=.60; servopos+=.03) {
- servo1=servopos+.2;
- servo2=servopos;
+ 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;
- counter1=counter%20;
- if (counter1==17) {
- LED=rand()%129;
+ 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);
+ wait (.025); //low wait time for smooth motion
}
for(servopos=.60; servopos>=.40; servopos-=.03) {
- servo1=servopos+.2;
- servo2=servopos;
+ 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;
- counter1=counter%20;
- if (counter1==17) {
- LED=rand()%129;
+ 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);
+ wait (.025); //low wait time for smooth motion
}
}
- while(Switch==0) {
- servo1=.7;
- servo2=.5;
- motorspeed=0;
+ 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);
}
}
