servo

Dependencies:   Servo mbed

main.cpp

Committer:
dantg
Date:
2018-10-30
Revision:
0:eb4e1282a821

File content as of revision 0:eb4e1282a821:

#include "mbed.h"
#include "Servo.h"

Serial pc(USBTX, USBRX); // USB serial interface
Servo my_srv(p21); // continuous rotation hobby servo
DigitalIn snsr30(p17);
DigitalIn snsr150(p18);
#define CR_SCALE 12.0
int main() {
 // set the USB serial interface baud rate
 pc.baud(921600);

 my_srv.calibrate(0.001,45);
 while(1) {
        if(snsr30 > 0.8) {
            my_srv.write(0.1666666);
            }
            wait(0.5);
        else {
            my_srv.write(0.5);
            }
            wait(0.5);
        if(snsr150 > 0.8) {
            my_srv.write(0.8333333);
            }
            wait(0.5);
        else {
            my_srv.write(0.5);
            }
            wait(0.5);
 }
}