Servo

Dependencies:   mbed MODSERIAL Servo FastPWM

Committer:
AnkePost
Date:
Fri Oct 11 08:41:58 2019 +0000
Revision:
2:381007cb7a70
Parent:
1:f6898c9b8c44
Child:
3:91b8945b659d
Script van internet dat wel werkt maar servomotor niet aanpast

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AnkePost 0:60a8a60074a7 1 #include "mbed.h"
AnkePost 0:60a8a60074a7 2 #include "Servo.h"
AnkePost 2:381007cb7a70 3
AnkePost 2:381007cb7a70 4 Servo myservo(D5);
AnkePost 0:60a8a60074a7 5 Serial pc(USBTX, USBRX);
AnkePost 2:381007cb7a70 6
AnkePost 2:381007cb7a70 7 int main() {
AnkePost 2:381007cb7a70 8 float range = 0.0005;
AnkePost 2:381007cb7a70 9 float position = 0.5;
AnkePost 2:381007cb7a70 10 float state = 0.1f;
AnkePost 2:381007cb7a70 11 pc.printf("I am on\n");
AnkePost 2:381007cb7a70 12 myservo.calibrate (range, 90.0);
AnkePost 2:381007cb7a70 13
AnkePost 2:381007cb7a70 14
AnkePost 2:381007cb7a70 15 while (1){
AnkePost 2:381007cb7a70 16 pc.printf("start new!");
AnkePost 2:381007cb7a70 17 myservo = 0.5;
AnkePost 2:381007cb7a70 18 wait(1);
AnkePost 2:381007cb7a70 19 state = myservo.read();
AnkePost 2:381007cb7a70 20 pc.printf("Current: %.5f \n", state);
AnkePost 2:381007cb7a70 21 state = 0;
AnkePost 2:381007cb7a70 22 wait(1);
AnkePost 2:381007cb7a70 23
AnkePost 2:381007cb7a70 24 myservo.position(-45);
AnkePost 2:381007cb7a70 25 wait(1);
AnkePost 2:381007cb7a70 26 state = myservo.read();
AnkePost 2:381007cb7a70 27 pc.printf("Current: %.5f \n", state);
AnkePost 2:381007cb7a70 28 state = 0;
AnkePost 2:381007cb7a70 29 wait(1);
AnkePost 1:f6898c9b8c44 30
AnkePost 2:381007cb7a70 31 myservo.position(0);
AnkePost 2:381007cb7a70 32 wait(1);
AnkePost 2:381007cb7a70 33 state = myservo.read();
AnkePost 2:381007cb7a70 34 pc.printf("Current: %.5f \n", state);
AnkePost 2:381007cb7a70 35 state = 0;
AnkePost 2:381007cb7a70 36 wait(1);
AnkePost 2:381007cb7a70 37
AnkePost 2:381007cb7a70 38 myservo.position(30);
AnkePost 2:381007cb7a70 39 wait(1);
AnkePost 2:381007cb7a70 40 state = myservo.read();
AnkePost 2:381007cb7a70 41 pc.printf("Current: %.2f \n", state);
AnkePost 2:381007cb7a70 42 state = 0;
AnkePost 2:381007cb7a70 43 wait(1);
AnkePost 2:381007cb7a70 44
AnkePost 2:381007cb7a70 45 myservo.position(45);
AnkePost 2:381007cb7a70 46 wait(1);
AnkePost 2:381007cb7a70 47 state = myservo.read();
AnkePost 2:381007cb7a70 48 pc.printf("Current: %.2f \n", state);
AnkePost 2:381007cb7a70 49 state = 0;
AnkePost 2:381007cb7a70 50 wait(1);
AnkePost 2:381007cb7a70 51
AnkePost 2:381007cb7a70 52 myservo.position(90);
AnkePost 2:381007cb7a70 53 wait(1);
AnkePost 2:381007cb7a70 54 state = myservo.read();
AnkePost 2:381007cb7a70 55 pc.printf("Current: %.2f \n", state);
AnkePost 2:381007cb7a70 56 state = 0;
AnkePost 2:381007cb7a70 57 wait(1);
AnkePost 0:60a8a60074a7 58 }
AnkePost 0:60a8a60074a7 59 }