This program sets the position of the motor by taking input from switches

Dependencies:   Servo mbed

Committer:
EduRemo
Date:
Fri Feb 05 07:32:01 2016 +0000
Revision:
0:9c4154e40f94
FRCRCE

Who changed what in which revision?

UserRevisionLine numberNew contents of line
EduRemo 0:9c4154e40f94 1 // Hello World to sweep a servo through its full range
EduRemo 0:9c4154e40f94 2
EduRemo 0:9c4154e40f94 3 #include "mbed.h"
EduRemo 0:9c4154e40f94 4 #include "Servo.h"
EduRemo 0:9c4154e40f94 5
EduRemo 0:9c4154e40f94 6 Servo myservo(PTC1);
EduRemo 0:9c4154e40f94 7
EduRemo 0:9c4154e40f94 8 DigitalIn sw0(PTD1); // Switch selected as input
EduRemo 0:9c4154e40f94 9 DigitalIn sw1(PTD3);
EduRemo 0:9c4154e40f94 10 DigitalIn sw2(PTD2);
EduRemo 0:9c4154e40f94 11 DigitalIn sw3(PTD0);
EduRemo 0:9c4154e40f94 12
EduRemo 0:9c4154e40f94 13 int main()
EduRemo 0:9c4154e40f94 14 {
EduRemo 0:9c4154e40f94 15 while(1)
EduRemo 0:9c4154e40f94 16 {
EduRemo 0:9c4154e40f94 17 if (sw0==0 && sw1==1 && sw2==1 && sw3==1)
EduRemo 0:9c4154e40f94 18 {
EduRemo 0:9c4154e40f94 19 myservo = 99/100.0;
EduRemo 0:9c4154e40f94 20 wait(0.5);
EduRemo 0:9c4154e40f94 21 }
EduRemo 0:9c4154e40f94 22 else if (sw0==1 && sw1==0 && sw2==1 && sw3==1)
EduRemo 0:9c4154e40f94 23 {
EduRemo 0:9c4154e40f94 24 myservo = 66/100.0;
EduRemo 0:9c4154e40f94 25 wait(0.5);
EduRemo 0:9c4154e40f94 26 }
EduRemo 0:9c4154e40f94 27 else if (sw0==1 && sw1==1 && sw2==0 && sw3==1)
EduRemo 0:9c4154e40f94 28 {
EduRemo 0:9c4154e40f94 29 myservo = 33/100.0;
EduRemo 0:9c4154e40f94 30 wait(0.5);
EduRemo 0:9c4154e40f94 31 }
EduRemo 0:9c4154e40f94 32 else if (sw0==1 && sw1==1 && sw2==1 && sw3==0)
EduRemo 0:9c4154e40f94 33 {
EduRemo 0:9c4154e40f94 34 myservo = 1/100.0;
EduRemo 0:9c4154e40f94 35 wait(0.5);
EduRemo 0:9c4154e40f94 36 }
EduRemo 0:9c4154e40f94 37 else
EduRemo 0:9c4154e40f94 38 {
EduRemo 0:9c4154e40f94 39 myservo = 50/100.0;
EduRemo 0:9c4154e40f94 40 wait(0.5);
EduRemo 0:9c4154e40f94 41 }
EduRemo 0:9c4154e40f94 42 }
EduRemo 0:9c4154e40f94 43 }