add servos

Dependencies:   Servo1 mbed

Fork of ES200_Project2 by Project 2

Files at this revision

API Documentation at this revision

Comitter:
m211656
Date:
Thu Oct 18 19:10:52 2018 +0000
Parent:
0:b6a454c0b00a
Commit message:
Add servos

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r b6a454c0b00a -r 852f86d263c8 main.cpp
--- a/main.cpp	Thu Oct 11 19:15:00 2018 +0000
+++ b/main.cpp	Thu Oct 18 19:10:52 2018 +0000
@@ -5,36 +5,40 @@
 Servo myservo(p21);
 Servo myservo2(p22);
 Motor m(p26,p30,p29);
-DigitalIn sw1=(p16), sw2=(p17), sw3=(p18), sw4=(p19), sw5=(p20);
-BusOut lights(p5,p6,p7,p8,p9);
+DigitalIn sw1(p15), sw2(p16), sw3(p17), sw4(p18), sw5(p19);
+BusOut lights(p5,p6,p7,p10,p11);
 
 
 int main()
 {
     while(1) 
     {
-        if(sw1==1) {
-            lights=1;
-            //myservo motor on
+        wait(0.5);
+        if(sw5==1) { //servo1 off
+            lights=31;
+            printf("light 5 is on\n\r");
         }
-        if(sw2==1) {
-            lights=3;
-            //m turns on
+        else if(sw4==1) { //dc motor off
+            lights=15;
+            printf("light 4 is on\n\r");
+            m.speed(0.0);
             }
-        if(sw3==1) {
+        else if(sw3==1) { //servo2 on
             lights=7;
-            //myservo2 on
+            printf("light 3 is on\n\r");
             }
-        if(sw4==1) {
-            lights=0xF;
-            //dc motor off
+        else if(sw2==1) { //dc motor on
+            lights=3;
+            printf("light 2 is on\n\r");
+            m.speed(1.0);
             }
-        if(sw5==1) {
-            lights=0x1F;//wrong hex number?----need 11111 in hex
-            //servo motor off, all lights on
+        else if(sw1==1) { //servo1 comes on
+            lights=1;
+             printf("light 1 is on\n\r");
             }
         else {
-            lights=0;} //no switches on = no lights on
+            lights=0; //no switches on = no lights or motors on
+            m.speed(0.0);}
         
     }
 }