versuch 2

Dependencies:   mbed

Committer:
corsa1600
Date:
Mon Jun 24 05:33:30 2019 +0000
Revision:
0:b74c2c5f64c1
versuch2

Who changed what in which revision?

UserRevisionLine numberNew contents of line
corsa1600 0:b74c2c5f64c1 1 // Steuerung des R-Servo mit Tasten
corsa1600 0:b74c2c5f64c1 2
corsa1600 0:b74c2c5f64c1 3 #include "mbed.h"
corsa1600 0:b74c2c5f64c1 4 #include "servo.h"
corsa1600 0:b74c2c5f64c1 5
corsa1600 0:b74c2c5f64c1 6 DigitalIn Rechts(P0_15);
corsa1600 0:b74c2c5f64c1 7 DigitalIn Links(P0_10);
corsa1600 0:b74c2c5f64c1 8 DigitalIn RangePlus(P0_23);
corsa1600 0:b74c2c5f64c1 9 DigitalIn RangeMinus(P1_16);
corsa1600 0:b74c2c5f64c1 10
corsa1600 0:b74c2c5f64c1 11 Servo myservo(P0_8); // p6
corsa1600 0:b74c2c5f64c1 12
corsa1600 0:b74c2c5f64c1 13 int main()
corsa1600 0:b74c2c5f64c1 14 {
corsa1600 0:b74c2c5f64c1 15 float range = 0.0005;
corsa1600 0:b74c2c5f64c1 16 float position = 0.5;
corsa1600 0:b74c2c5f64c1 17
corsa1600 0:b74c2c5f64c1 18 while(1)
corsa1600 0:b74c2c5f64c1 19 {
corsa1600 0:b74c2c5f64c1 20 if(Rechts)
corsa1600 0:b74c2c5f64c1 21 position = 0.0;
corsa1600 0:b74c2c5f64c1 22 if(Links)
corsa1600 0:b74c2c5f64c1 23 position = 1.0;
corsa1600 0:b74c2c5f64c1 24 if(Rechts && Links)
corsa1600 0:b74c2c5f64c1 25 {
corsa1600 0:b74c2c5f64c1 26 position = 0.5;
corsa1600 0:b74c2c5f64c1 27 wait_ms(100);
corsa1600 0:b74c2c5f64c1 28 }
corsa1600 0:b74c2c5f64c1 29 if(RangePlus)
corsa1600 0:b74c2c5f64c1 30 {
corsa1600 0:b74c2c5f64c1 31 range += 0.0001;
corsa1600 0:b74c2c5f64c1 32 wait_ms(100);
corsa1600 0:b74c2c5f64c1 33 }
corsa1600 0:b74c2c5f64c1 34 if(RangeMinus)
corsa1600 0:b74c2c5f64c1 35 {
corsa1600 0:b74c2c5f64c1 36 range -= 0.0001;
corsa1600 0:b74c2c5f64c1 37 wait_ms(100);
corsa1600 0:b74c2c5f64c1 38 }
corsa1600 0:b74c2c5f64c1 39 myservo.calibrate(range, 45.0);
corsa1600 0:b74c2c5f64c1 40 myservo = position;
corsa1600 0:b74c2c5f64c1 41 wait_ms(500);
corsa1600 0:b74c2c5f64c1 42 }
corsa1600 0:b74c2c5f64c1 43 }