Fa2018-es200-3321-proj2-GoodTeam#2 / Mbed 2 deprecated Project_2_Code

Dependencies:   mbed Motor Servo

Revision:
2:b4a690fadc9b
Parent:
1:d90f940d6ed2
Child:
3:770e110905d9
--- a/main.cpp	Tue Oct 09 14:36:47 2018 +0000
+++ b/main.cpp	Tue Oct 09 15:43:44 2018 +0000
@@ -4,39 +4,40 @@
 #include "mbed.h"
 #include "stdio.h"
 #include "stdlib.h"
+#include "Motor.h"
+#include "Servo.h"
 
-/*
-Declare servos, motors, and switches
-Hardware:
-Servo 1 – rotates hand between palm facing up and palm facing in
-Servo 2 – inside jar to burst pb out
-Motor – drive arm from 90 degrees to forehead
-Switch 1 – in palm (when pb jar is put in the hand, hits the switch to activate the servo on the hand)
-Switch 2 – on forehead (turn motor off)
-Switch 3 – on lid? (when you put the contents back in the jar it signals arm to start moving back down to starting position?)
-Switch 4 – on (desk?) to signal the motor to stop when arm reaches starting position
-*/
+//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
 
 int main() {
-/*
-Software:
-Hand starts with palm facing in
-Jar into hand
+
+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)
+
+/*Hand starts with palm facing in
+User puts jar into hand
 Hits switch that turns servo on to turn the hand to position where palm is facing up
 Motor drives arm from elbow at 90 degrees up to forehead (hit switch to turn motor off)
 (I don’t know if this next step will happen as a result of the same switch that turned the motor off or with a different switch)
-Random number (Russian roulette) if the jar will open or not
-            Rand_Max / (int) random //random integer 0 or 1
-/*This next section depends on if the random number is 0 or 1*/
-/*If open (read 1):
+Random number if the jar will open or not
+    int a = rand()%1; //Generate random integer 0 or 1
+If open -- if (a == 1)
 When switch is hit to turn motor off? Servo inside jar turns on to break the lid and make pb fall out
-Speaker will go off saying “beat Army”
+Speaker will go off saying “beat Army” - send code through MatLab
 When user puts contents back in the jar and lid on, hits a switch (when lid goes back on?) that turns the motor on to return the arm to the original position
 When switch 4 is hit, motor will turn off
 Servo 1 will turn on (with the same switch that turned motor off if possible) returning the hand to the original position
-If stay closed (read 0):
+
+If stay closed -- if (a == 0)
             Servo inside pb jar will not turn on
-            Speaker will say “boo”
+            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?
 */
-}
+}
\ No newline at end of file