Test code

Dependencies:   mbed Motor Servo

Revision:
2:17956bff3ff2
Parent:
1:bd813dd636a9
Child:
3:638dced18d87
diff -r bd813dd636a9 -r 17956bff3ff2 main.cpp
--- a/main.cpp	Tue Oct 09 15:05:03 2018 +0000
+++ b/main.cpp	Fri Oct 12 14:45:12 2018 +0000
@@ -7,16 +7,16 @@
 #include "mbed.h"
 #include "Servo.h" //need Servo library
 
-Motor m(p, p, p); //designates the pins used by the motor
-Servo servo1(p);
-Servo servo2(p);
-DigitalIn sw1(p); //switches or buttons
-DigitalIn bu1(p); //Army man
-DigitalIn bu2(p); //Army man
-DigitalIn bu3(p); //Army man
-DigitalIn bu4(p); //Motor clockwise
-DigitalIn bu5(p); //Motor CC
-DigitalOut leds[5]={p,p,p,p,p};
+Motor m(p29, p30, p26); //designates the pins used by the motor
+Servo servo1(p21);
+Servo servo2(p22);
+DigitalIn sw1(p16); //switches or buttons
+DigitalIn bu1(p24); //Army man
+//DigitalIn bu2(p); //Army man
+//DigitalIn bu3(p); //Army man
+//DigitalIn bu4(p); //Motor clockwise
+//DigitalIn bu5(p); //Motor CC
+DigitalOut leds[3]={p25, p26, p27};
 float pos = rand()/(float)RAND_MAX; //allows the servo to start at a random position 
 float pos2 = rand()/(float)RAND_MAX;
 int sw1state, bu1state, bu2state, bu3state, bu4state, bu5state; //the state of the switch
@@ -32,17 +32,19 @@
     while(1) { //do we need while?
         sw1state=sw1.read(); //read in switch state
         bu1state=bu1.read();
-        bu2state=bu2.read();
-        bu3state=bu3.read();
-        bu4state=bu4.read();
-        bu5state=bu5.read();
-        pos=0
-        pos2=0
-    
-        if((sw1state) == 1) { //if switch is on move servos quickly to other angle
-            (pos && pos2) = 1;}
-        if((sw1state) == 1) { //if switch is off move back
-            (pos && pos2) = 0;}
+        //bu2state=bu2.read();
+        //bu3state=bu3.read();
+        //bu4state=bu4.read();
+        //bu5state=bu5.read();
+        pos=0;
+        pos2=0;
+        
+        if (sw1state == 1) { //if bu4 is on rotate motor fwd
+            m.speed(s);
+            s=1;}
+        if (sw1state == 0) { //if bu5 is on rotate motor rev
+            m.speed(-s);
+            s=0;}
             
             
         if (bu1state == 0) { //if ARMY button is off light up LEDS
@@ -59,10 +61,10 @@
             leds[2]=0;}
         
         
-        if (bu4state == 1) { //if bu4 is on rotate motor fwd
-            m.speed(s);}
-        if (bu5state == 1) { //if bu5 is on rotate motor rev
-            m.speed(-s);}
+        //if((sw1state) == 1) { //if switch is on move servos quickly to other angle
+        //    (pos && pos2) = 1;}
+        //if((sw1state) == 1) { //if switch is off move back
+        //    (pos && pos2) = 0;}
         
     } //end while
 } //end main