It begins

Dependencies:   SDFileSystem mbed-rtos mbed wave_player

Fork of BAT_senior_design by BAT

Committer:
nnguyen45
Date:
Fri Oct 06 13:33:52 2017 +0000
Revision:
2:6836f515bb50
Parent:
1:4347df0fafb1
Child:
3:9ed43e974156
hi

Who changed what in which revision?

UserRevisionLine numberNew contents of line
aismail1997 0:9eda4611081a 1 #include "mbed.h"
aismail1997 0:9eda4611081a 2 #include "Servo.h"
aismail1997 0:9eda4611081a 3
aismail1997 0:9eda4611081a 4 PwmOut myservo(p21);
aismail1997 0:9eda4611081a 5 DigitalIn pb1 (p20);
aismail1997 0:9eda4611081a 6 //AnalogIn linpot(p20);
aismail1997 0:9eda4611081a 7 Serial pc(USBTX, USBRX);
aismail1997 0:9eda4611081a 8 DigitalOut myled(LED1);
aismail1997 0:9eda4611081a 9
aismail1997 0:9eda4611081a 10 int main()
aismail1997 0:9eda4611081a 11 {
aismail1997 0:9eda4611081a 12 // button up: state = 0, button halfway: state = 1; button down: state = 2
aismail1997 0:9eda4611081a 13 //int state = 0;
aismail1997 0:9eda4611081a 14 pc.printf("begin\n");
aismail1997 0:9eda4611081a 15 int state = 2;
aismail1997 0:9eda4611081a 16 pb1.mode(PullUp);
aismail1997 0:9eda4611081a 17 wait(.001);
aismail1997 0:9eda4611081a 18 for(int i=0; i<=3; i++) {
aismail1997 0:9eda4611081a 19 myservo = i/100.0;
aismail1997 0:9eda4611081a 20 wait(0.01);
aismail1997 0:9eda4611081a 21 }
aismail1997 0:9eda4611081a 22 while(1) {
aismail1997 0:9eda4611081a 23 // Servo code
aismail1997 0:9eda4611081a 24 if (pb1 == 1 && state == 2) {
aismail1997 0:9eda4611081a 25 while(pb1 == 1)
aismail1997 0:9eda4611081a 26 myled = 1;
aismail1997 0:9eda4611081a 27 // rotate 90 degrees one way
aismail1997 0:9eda4611081a 28 for(int i=3; i<=7; i++) {
aismail1997 0:9eda4611081a 29 myservo = i/100.0;
aismail1997 0:9eda4611081a 30 wait(0.01);
aismail1997 0:9eda4611081a 31 }
aismail1997 0:9eda4611081a 32 state = 1;
aismail1997 0:9eda4611081a 33 }
aismail1997 0:9eda4611081a 34 //wait(1.0);
aismail1997 0:9eda4611081a 35 // rotate 90 degrees other way
aismail1997 0:9eda4611081a 36 if (pb1 == 1 && state == 1) {
aismail1997 0:9eda4611081a 37 while(pb1 == 1)
aismail1997 0:9eda4611081a 38 myled = 0;
aismail1997 0:9eda4611081a 39 for(int i=7; i>3; i--) {
aismail1997 0:9eda4611081a 40 myservo = i/100.0;
aismail1997 0:9eda4611081a 41 wait(0.01);
aismail1997 0:9eda4611081a 42 }
aismail1997 0:9eda4611081a 43 //wait(0.1);
aismail1997 0:9eda4611081a 44 state = 2;
aismail1997 0:9eda4611081a 45 }
aismail1997 0:9eda4611081a 46 //wait(1.0);
aismail1997 0:9eda4611081a 47
aismail1997 0:9eda4611081a 48 // read linear potentiometer
aismail1997 0:9eda4611081a 49 //if (linpot < 0.5) {
aismail1997 0:9eda4611081a 50 //float potval = linpot;
aismail1997 0:9eda4611081a 51 //pc.printf("linear pot: %f\n", potval);
aismail1997 0:9eda4611081a 52 }
aismail1997 0:9eda4611081a 53 }