
Program to restrict the movement of servos by using ReedSwitch
Diff: main.cpp
- Revision:
- 0:73919552e1de
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sat Dec 14 18:01:16 2013 +0000 @@ -0,0 +1,32 @@ +#include "mbed.h" +#include "Servo.h" + +DigitalIn rSwitch(D10); +Servo servoRotado(D11); + +int valSwitch; +float pos=0; + +int main() { + rSwitch.mode(PullUp); + servoRotado.calibrate(0.001, 45.0); + while(1) { + valSwitch=rSwitch; + + while(pos<=1 and valSwitch==1){ + valSwitch=rSwitch; + pos=pos+0.05; + servoRotado=pos; + wait(0.3); + } + while(pos>=0){ + pos=pos-0.05; + servoRotado=pos; + wait(0.3); + } + + + + + } +}