Servo_versuch

Dependencies:   Servo mbed

Committer:
Jannis
Date:
Thu Sep 14 07:37:50 2017 +0000
Revision:
0:0edb70dfa322
Servo_versuch

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Jannis 0:0edb70dfa322 1 #include "mbed.h"
Jannis 0:0edb70dfa322 2 #include "Servo.h"
Jannis 0:0edb70dfa322 3
Jannis 0:0edb70dfa322 4 Servo myservo(p26);
Jannis 0:0edb70dfa322 5 Serial pc(USBTX, USBRX);
Jannis 0:0edb70dfa322 6
Jannis 0:0edb70dfa322 7 int main() {
Jannis 0:0edb70dfa322 8
Jannis 0:0edb70dfa322 9 pc.baud(4800);
Jannis 0:0edb70dfa322 10
Jannis 0:0edb70dfa322 11 printf("Servo Calibration Controls:\n");
Jannis 0:0edb70dfa322 12 printf("1,2,3 - Position Servo (full left, middle, full right)\n");
Jannis 0:0edb70dfa322 13 printf("4,5 - Decrease or Increase range\n");
Jannis 0:0edb70dfa322 14
Jannis 0:0edb70dfa322 15 float range = 0.0005;
Jannis 0:0edb70dfa322 16 float position = 0.5;
Jannis 0:0edb70dfa322 17
Jannis 0:0edb70dfa322 18 while(1) {
Jannis 0:0edb70dfa322 19 switch(pc.getc()) {
Jannis 0:0edb70dfa322 20 case '1': position = 0.005; break;
Jannis 0:0edb70dfa322 21 case '2': position = 0.502; break;
Jannis 0:0edb70dfa322 22 case '3': position = 1.050; break;
Jannis 0:0edb70dfa322 23 case '4': range += 0.0001; break;
Jannis 0:0edb70dfa322 24 case '5': range -= 0.0001; break;
Jannis 0:0edb70dfa322 25 case '6': position = 0.005;
Jannis 0:0edb70dfa322 26 while (position < 1.0)
Jannis 0:0edb70dfa322 27 {
Jannis 0:0edb70dfa322 28 position += 0.001;
Jannis 0:0edb70dfa322 29 wait_ms(25);
Jannis 0:0edb70dfa322 30 myservo = position;
Jannis 0:0edb70dfa322 31
Jannis 0:0edb70dfa322 32 float wert = myservo.read();
Jannis 0:0edb70dfa322 33 printf("read: %.3f", wert);
Jannis 0:0edb70dfa322 34
Jannis 0:0edb70dfa322 35 if (position >= 0.998)
Jannis 0:0edb70dfa322 36 position = 0.0;
Jannis 0:0edb70dfa322 37 }
Jannis 0:0edb70dfa322 38
Jannis 0:0edb70dfa322 39 break;
Jannis 0:0edb70dfa322 40
Jannis 0:0edb70dfa322 41 }
Jannis 0:0edb70dfa322 42 printf("position = %.1f, range = +/-%0.4f\n", position, range);
Jannis 0:0edb70dfa322 43 myservo.calibrate(range, 90.0);
Jannis 0:0edb70dfa322 44 myservo = position;
Jannis 0:0edb70dfa322 45 float wert = myservo.read();
Jannis 0:0edb70dfa322 46 printf("read: %.3f", wert);
Jannis 0:0edb70dfa322 47
Jannis 0:0edb70dfa322 48 }
Jannis 0:0edb70dfa322 49 }