Test code

Dependencies:   mbed Motor Servo

Files at this revision

API Documentation at this revision

Comitter:
m215910
Date:
Fri Oct 19 14:44:13 2018 +0000
Parent:
3:638dced18d87
Commit message:
both motors and button

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Tue Oct 16 15:43:29 2018 +0000
+++ b/main.cpp	Fri Oct 19 14:44:13 2018 +0000
@@ -9,17 +9,17 @@
 #include "Servo.h" //need Servo library
 
 Motor m(p26, p30, p29); //designates the pins used by the motor
-Servo servo1(p21);
-Servo servo2(p22);
+//Servo servo1(p21);
+//Servo servo2(p22);
 DigitalIn sw1(p16); //switches or buttons
-DigitalIn bu1(p15); //Army man
-DigitalIn bu2(p14); //Army man
-//DigitalIn bu3(p); //Army man
+DigitalIn bu1(p21); //Army man
+DigitalIn bu2(p22); //Army man
+DigitalIn bu3(p23); //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;
+DigitalOut leds[3]={p10, p11, p12};
+//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
 int s=0.6; //speed of motor rotation - fairly slow so as to be exact
 
@@ -31,7 +31,7 @@
     //servo2=pos2;
     
     while(1) { //do we need while?
-        sw1state=sw1.read(); //read in switch state
+        //sw1state=sw1.read(); //read in switch state
         //bu1state=bu1.read();
         //bu2state=bu2.read();
         //bu3state=bu3.read();
@@ -40,8 +40,10 @@
         //pos=0;
         //pos2=0;
         
+        sw1state=sw1.read(); //read in switch state
+        
         if (sw1state == 1) { //if bu4 is on rotate motor fwd
-            m.speed(s);
+            m.speed(-s);
             s=1;
             printf("hi");}
             else { //if bu5 is on rotate motor rev
@@ -49,18 +51,23 @@
             s=0;}
             
             
-        //if (bu1state == 0) { //if ARMY button is off light up LEDS
-        //    leds[0]=1;}
-        //    else {
-        //    leds[0]=0;}
-        //if (bu2state == 0) {
-        //    leds[1]=1;}
-        //    else {
-        //    leds[1]=0;}
-        //if (bu3state == 0) {
-        //    leds[2]=1;}
-        //    else {
-        //    leds[2]=0;}
+        bu1state=bu1.read();
+        bu2state=bu2.read();
+        bu3state=bu3.read();
+        
+         
+        if (bu1state == 0) { //if ARMY button is off light up LEDS
+            leds[0]=1;}
+        if (bu1state == 1) {
+            leds[0]=0;}
+        if (bu2state == 0) { //if ARMY button is off light up LEDS
+            leds[1]=1;}
+        if (bu2state == 1) {
+            leds[1]=0;}
+        if (bu3state == 0) { //if ARMY button is off light up LEDS
+            leds[2]=1;}
+        if (bu3state == 1) {
+            leds[2]=0;}
         
         
         //if((sw1state) == 1) { //if switch is on move servos quickly to other angle