Pseudo Code

Dependencies:   mbed Motor Servo

Revision:
4:8079e89199ff
Parent:
3:770e110905d9
--- a/main.cpp	Tue Oct 16 14:46:15 2018 +0000
+++ b/main.cpp	Mon Oct 22 14:06:02 2018 +0000
@@ -8,55 +8,55 @@
 #include "Servo.h"
 
 //Declare servos, motors, and switches
-Servo servo_1(p#);//rotates hand between palm facing up and palm facing in
-Servo servo_2(p#); //inside jar to burst pb out
-Motor motor(p#, p#, p#); // drive arm from 90 degrees to forehead
-DigitalIn switch_1(p#); //in palm (when pb jar is put in the hand, hits the switch to activate the servo on the hand)
-DigitalIn switch_2(p#); //on forehead (turn motor off)
-DigitalIn switch_3(p#); //on lid? (when you put the contents back in the jar it signals arm to start moving back down to starting position?)
-DigitalIn switch_4(p#); //on (desk?) to signal the motor to stop when arm reaches starting position
+Servo servo_1(p24);//rotates hand between palm facing up and palm facing in
+Servo servo_2(p21); //on jar to rotate it in hand
+Motor motor(p29, p30, p26); // drive arm from 90 degrees to forehead
+//DigitalIn switch_1(p#); //on protoboard - hit to start 
+DigitalIn switch_2(p18); //on "hand" - hits forehead to turn motor off
+//DigitalIn switch_3(p#); //on protoboard - returns arm to start position
+DigitalIn switch_4(p20); //on "hand" - hits desk when going down to turn motor off
 
 int main() {
+servo_1.calibrate(0.0009, 45.0); //Calibrates the servo_1 timing by setting the pulse width and range of motion (45*2 = 90 degrees)
+servo_2.calibrate(0.0009, 90.0); //Calibrates the servo_2 timing by setting the pulse width and range of motion (45*2 = 90 degrees)
 
-servo_1.calibrate(0.0009, 45.0); //Calibrates the servo_1 timing by setting the pulse width and range of motion (45*2 = 90 degrees)
-servo_2.calibrate(0.0009, 45.0); //Calibrates the servo_2 timing by setting the pulse width and range of motion (45*2 = 90 degrees)
-servo_1.write(0.5); //Or what ever number sets the servo in the initial position
+while(!switch_1)
+servo_1.write(.25); //Sets the servo in the initial position - palm facing in
+servo_2.write(0); //Sets the servo in the initial position - Does not matter where
 
-/*Hand starts with palm facing in
-User puts jar into hand
-Hits switch (wait a set time before turning servo on) that turns servo on to turn the hand to position where palm is facing up
-if (switch_1.read() == 1) {
-    wait (...);
-    servo_1.write(1.0); //or whatever number sets the servo to the "palm up" position
-    wait (...);
-    motor.speed(...);} 
+if (switch_1.read() == 1) //User hits switch 1 (button on protoboard)
+{
+int i=0;                    //declare i as an integer and initialize it to 0
+for (i=0; i<=10; i++)       //rotate the pb jar for a cycle of 10 counts
+ {      servo_2.write(0.0);   //initial position
+        servo_2.write(1.0);  //final position 
+ }
+servo_1.write(.75); //turn the hand to the "palm up" position
+wait (2);           //wait for hand to get into "palm up" position
+motor.speed(.7);    //turn motor on to drive arm up
 
-Motor drives arm from elbow at 90 degrees up to forehead (hit switch to turn motor off)
-if (switch_2.read() == 1) {
-    motor.speed(0);
-    int a = rand()%1; //Generate random integer 0 or 1 to determine if the jar will open or not}
+if (switch_2.read() == 2)    //when switch hits forehead
+{motor.speed(0);   //turn motor off
+int a = rand()%1;} //Generate random integer 0 or 1 to determine if the jar will open or not - what sound will play and if jar opens
 
 if (a == 1) {
-    servo_2.write(1.0); //Servo inside jar turns on to break the lid and make pb fall out
-    
-    pc.printf("1\n"); // send signal to Matlab to play sound
-      wait(10.0); // wait for Matlab to finish playing the sound
+    servo_1.write(...); //Servo on wrist turns to allow pb to come out
+    pc.printf("1\n"); // send signal to Matlab to play Beat Army sound
+    wait(10.0); // wait for Matlab to finish playing the sound NATHAN'S CODE???
       
-Speaker will go off saying “beat Army” - send code through MatLab
-if (switch_3.read() == 1) //When user puts contents back in the jar and lid on, hits a switch (when lid goes back on?)
-{ motor.speed(-...); //turns the motor on to return the arm to the original position
-
-}
 else if (a == 0)
 {
-            Servo inside pb jar will not turn on
-            Speaker will say “boo” - send code through MatLab
-            }
---switch will not be hit when lid goes back (since it never came off) so will the user have to manually move the arm back to the starting position? Will they press the button on the lid so the motor turns on?
+    pc.printf("2\n"); // send signal to Matlab to play boo sound
+    wait(10.0); // wait for Matlab to finish playing the sound NATHAN'S CODE???
+}
 
-if (switch_4.read() == 1)// When switch 4 is hit {
+if (switch_3.read() == 1) //When user is ready to return arm to start position, hits switch_3 on protoboard
+{ motor.speed(-.5); //turns the motor on to return the arm to the original position
+}
+
+if (switch_4.read() == 1)// When switch 4 is hit 
     motor.speed(0); // motor will turn off
-    servo_1.write(...) //Servo 1 will turn on returning the hand to the original position
+    wait(1);        //wait 1 second for arm to level out
+    servo_1.write(.25) //Servo 1 will turn on returning the hand to the original "palm in" position
     }
-*/
-}
\ No newline at end of file
+*/
\ No newline at end of file