![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Servo
Dependencies: mbed MODSERIAL Servo FastPWM
Revision 2:381007cb7a70, committed 2019-10-11
- Comitter:
- AnkePost
- Date:
- Fri Oct 11 08:41:58 2019 +0000
- Parent:
- 1:f6898c9b8c44
- Child:
- 3:91b8945b659d
- Commit message:
- Script van internet dat wel werkt maar servomotor niet aanpast
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Fri Oct 11 08:35:27 2019 +0000 +++ b/main.cpp Fri Oct 11 08:41:58 2019 +0000 @@ -1,19 +1,59 @@ -// Hello World to sweep a servo through its full range - #include "mbed.h" #include "Servo.h" -#include <math.h> - + +Servo myservo(D5); Serial pc(USBTX, USBRX); - -Servo myservo(D5); + +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); -int main() -{ - for(float p=0; p<1.0; p += 0.1) - { - myservo = p; - wait(0.5); - pc.printf("hello!"); + 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); } } \ No newline at end of file