StepSense
/
HW5_Servo
servo and photoresistors
main.cpp
- Committer:
- adarsh5723
- Date:
- 2014-11-10
- Revision:
- 1:19dd18051447
- Parent:
- 0:9898eeeb7143
File content as of revision 1:19dd18051447:
// Hello World to sweep a servo through its full range #include "mbed.h" #include "Servo.h" DigitalIn toggleSwitch(D3); AnalogIn ldr0(A5); PwmOut servoDriver(D2); Servo myservo(D2); //change digital pin here #define THRESHOLD .001 int counter = 0; Serial pc(USBTX, USBRX); int main() { //myservo.position(270.0f); myservo.calibrate(.0006, 120.0); bool servoLogic = 0; while(1){ #if 1 if (toggleSwitch == 1) //if (ldr0.read() > 0.7) servoLogic = 1; else servoLogic = 0; //recieve_data(ServoLogic); if (servoLogic) { float o = 0.0; myservo = o; } else{ float f= 1; myservo = f; } printf("%f\n\r",ldr0.read()); #else #if 0 int pos = 0; for(pos = 0; pos < 100; pos += 1) // goes from 0 degrees to 180 degrees { // in steps of 1 degree myservo = pos/100; // tell servo to go to position in variable 'pos' wait(0.015); // waits 15ms for the servo to reach the position } for(pos = 100; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees { myservo = pos/100; // tell servo to go to position in variable 'pos' wait(0.015); // waits 15ms for the servo to reach the position } #else myservo = 2; #endif #endif wait(.2); } }