Start of project 2

Dependencies:   Motor Servo mbed mbed-rtos

Committer:
nhersom
Date:
Wed Oct 10 12:33:06 2018 +0000
Revision:
4:a3e95c9d56d5
Parent:
2:60a8105d0d20
Parent:
3:50cee0fef078
Child:
5:27689dbb0c6e
updated code

Who changed what in which revision?

UserRevisionLine numberNew contents of line
m215676 0:9347308e8e1a 1 #include "mbed.h"
m215676 0:9347308e8e1a 2 #include "stdio.h"
m215676 0:9347308e8e1a 3 #include "Motor.h"
m215676 0:9347308e8e1a 4 #include "math.h"
m215676 2:60a8105d0d20 5 #include "Servo.h"
m215676 0:9347308e8e1a 6
m215676 1:7133819e4265 7 int s1, s3, s4, i;
m215676 2:60a8105d0d20 8 float x;
m215676 1:7133819e4265 9 DigitalIn swtch1(p19);
m215676 1:7133819e4265 10 DigitalIn swtch3(p20);
m215676 1:7133819e4265 11 DigitalIn swtch4(p21);
m215676 2:60a8105d0d20 12 AnalogIn turn(p22);
m215676 0:9347308e8e1a 13 Motor m(p26, p30, p29);
nhersom 4:a3e95c9d56d5 14 DigitalIn sw1 (p16) ;
m215676 1:7133819e4265 15
m215676 1:7133819e4265 16 Servo back(p21);
m215676 1:7133819e4265 17 Servo angle(p22);
m215676 0:9347308e8e1a 18
m215676 0:9347308e8e1a 19 int main() {
m215676 1:7133819e4265 20 s1 = swtch1.read(); //read state of switch 1
m215676 1:7133819e4265 21 back.calibrate(0.0009, 90.0); //calculate's servos timing by setting pulse width and range
m215676 0:9347308e8e1a 22
m215676 1:7133819e4265 23 while (s1 == 1)
m215676 1:7133819e4265 24 {
m215676 1:7133819e4265 25 for (i = 0; i < 18; i++) //moves monument forward
m215676 1:7133819e4265 26 {
m215676 1:7133819e4265 27 back = 0;
m215676 1:7133819e4265 28 back = (0.0 + (i/18.0));
m215676 1:7133819e4265 29 s1 = swtch1.read(); //read state of switch 1
m215676 1:7133819e4265 30 }//end of for loop
m215676 1:7133819e4265 31
m215676 1:7133819e4265 32 for (i = 0; i < 35; i++) //moves monument backwards
m215676 1:7133819e4265 33 {
m215676 1:7133819e4265 34 back = 1;
m215676 1:7133819e4265 35 back = (1.0 - (i/18.0));
m215676 1:7133819e4265 36 s1 = swtch1.read(); //read state of switch 1
m215676 1:7133819e4265 37 }//end of for loop
m215676 1:7133819e4265 38
m215676 1:7133819e4265 39 }//end of while loop
m215676 1:7133819e4265 40
m215676 2:60a8105d0d20 41
m215676 2:60a8105d0d20 42 while (1)
m215676 2:60a8105d0d20 43 {
m215676 2:60a8105d0d20 44 x = turn.read();
m215676 2:60a8105d0d20 45 angle = x;
m215676 2:60a8105d0d20 46 wait (.05);
m215676 2:60a8105d0d20 47
m215676 2:60a8105d0d20 48 } //end of while loop
nhersom 4:a3e95c9d56d5 49
nhersom 4:a3e95c9d56d5 50 sw1.read();
nhersom 4:a3e95c9d56d5 51 if (sw1==1) {
nhersom 3:50cee0fef078 52 while(1) {
nhersom 3:50cee0fef078 53 m.speed(1);
nhersom 3:50cee0fef078 54 wait (.15);
nhersom 3:50cee0fef078 55 m.speed(0);
nhersom 3:50cee0fef078 56 wait (1);
nhersom 3:50cee0fef078 57 break;
nhersom 3:50cee0fef078 58 }
nhersom 3:50cee0fef078 59 while(1) {
nhersom 3:50cee0fef078 60 m.speed(-.25);
nhersom 3:50cee0fef078 61 wait(.6);
nhersom 3:50cee0fef078 62 m.speed(0);
nhersom 3:50cee0fef078 63 wait(1);
nhersom 3:50cee0fef078 64 break;
nhersom 3:50cee0fef078 65 }
nhersom 3:50cee0fef078 66 }
m215676 0:9347308e8e1a 67 } //end of int main