![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Servo
Dependencies: mbed MODSERIAL Servo FastPWM
Diff: main.cpp
- Revision:
- 3:91b8945b659d
- Parent:
- 2:381007cb7a70
- Child:
- 4:8ae0c82c2d60
diff -r 381007cb7a70 -r 91b8945b659d main.cpp --- a/main.cpp Fri Oct 11 08:41:58 2019 +0000 +++ b/main.cpp Fri Oct 11 08:51:26 2019 +0000 @@ -1,59 +1,21 @@ #include "mbed.h" #include "Servo.h" - -Servo myservo(D5); + Serial pc(USBTX, USBRX); - -int main() { - float range = 0.0005; - float position = 0.5; - float state = 0.1f; - pc.printf("I am on\n"); - myservo.calibrate (range, 90.0); - - - while (1){ - pc.printf("start new!"); - myservo = 0.5; - wait(1); - state = myservo.read(); - pc.printf("Current: %.5f \n", state); - state = 0; - wait(1); - - myservo.position(-45); - wait(1); - state = myservo.read(); - pc.printf("Current: %.5f \n", state); - state = 0; - wait(1); - - myservo.position(0); - wait(1); - state = myservo.read(); - pc.printf("Current: %.5f \n", state); - state = 0; - wait(1); - - myservo.position(30); - wait(1); - state = myservo.read(); - pc.printf("Current: %.2f \n", state); - state = 0; - wait(1); - - myservo.position(45); - wait(1); - state = myservo.read(); - pc.printf("Current: %.2f \n", state); - state = 0; - wait(1); - - myservo.position(90); - wait(1); - state = myservo.read(); - pc.printf("Current: %.2f \n", state); - state = 0; - wait(1); +Servo myservo(D5); + +int main() +{ + while(1) { + for(int i=0; i<100; i++) { + myservo = i/100.0; + wait(0.01); + pc.printf("Naar voren"); + } + for(int i=100; i>0; i--) { + myservo = i/100.0; + wait(0.01); + pc.printf("Naar achteren"); + } } } \ No newline at end of file