Pseudo Code

Dependencies:   mbed Motor Servo

main.cpp

Committer:
msilver
Date:
2018-10-22
Revision:
4:8079e89199ff
Parent:
3:770e110905d9

File content as of revision 4:8079e89199ff:

/*Project 2 – Mechatronics – MIDN Dietrich, Schwind, Silver*/

//Libraries
#include "mbed.h"
#include "stdio.h"
#include "stdlib.h"
#include "Motor.h"
#include "Servo.h"

//Declare servos, motors, and switches
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)

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

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

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_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???
      
else if (a == 0)
{
    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_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
    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
    }
*/