versuch 2

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
corsa1600
Date:
Mon Jun 24 05:33:30 2019 +0000
Commit message:
versuch2

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
servo.h Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r b74c2c5f64c1 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Jun 24 05:33:30 2019 +0000
@@ -0,0 +1,43 @@
+// Steuerung des R-Servo mit Tasten
+
+#include "mbed.h"
+#include "servo.h"
+
+DigitalIn Rechts(P0_15);
+DigitalIn Links(P0_10);
+DigitalIn RangePlus(P0_23);
+DigitalIn RangeMinus(P1_16);
+
+Servo myservo(P0_8); // p6
+
+int main() 
+{
+    float range = 0.0005;
+    float position = 0.5;
+
+    while(1) 
+    {
+        if(Rechts)
+        position = 0.0;
+        if(Links)
+        position = 1.0;
+        if(Rechts && Links)
+        {
+            position = 0.5;
+            wait_ms(100);
+        }
+        if(RangePlus)
+        {
+            range += 0.0001;
+            wait_ms(100);
+        }
+        if(RangeMinus)
+        {
+            range -= 0.0001;
+            wait_ms(100);
+        }
+        myservo.calibrate(range, 45.0);
+        myservo = position;
+        wait_ms(500);
+    }
+}
\ No newline at end of file
diff -r 000000000000 -r b74c2c5f64c1 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Mon Jun 24 05:33:30 2019 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400
\ No newline at end of file
diff -r 000000000000 -r b74c2c5f64c1 servo.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/servo.h	Mon Jun 24 05:33:30 2019 +0000
@@ -0,0 +1,38 @@
+//servo.h
+#ifndef MBED_SERVO_H
+#define MBED_SERVO_H
+
+#include "mbed.h"
+
+class Servo 
+{
+
+    public:
+    // Create a servo object connected to the specified PwmOut pin
+    Servo(PinName pin);
+
+    //** Set the servo position, normalised to it's full range
+    void write(float percent);
+
+    //** Read the servo motors current position
+    float read();
+
+    //** Set the servo position
+    void position(float degrees);
+
+    //** Allows calibration of the range and angles for a particular servo
+    void calibrate(float range = 0.0005, float degrees = 45.0);
+
+    /** Shorthand for the write and read functions */
+    Servo& operator= (float percent);
+    Servo& operator= (Servo& rhs);
+    operator float();
+
+    protected:
+    PwmOut _pwm;
+    float _range;
+    float _degrees;
+    float _p;
+};
+
+#endif
\ No newline at end of file