Matthias Grob / Mbed 2 deprecated FlyBed3

Dependencies:   mbed

Committer:
maetugr
Date:
Tue Sep 08 13:38:10 2015 +0000
Revision:
0:37f0c1e8fa66
MPU9250 on the new Board works fine over SPI; RC is broken and works with FlyBed2 :(

Who changed what in which revision?

UserRevisionLine numberNew contents of line
maetugr 0:37f0c1e8fa66 1 // based on http://mbed.org/users/jdenkers/code/Servo/
maetugr 0:37f0c1e8fa66 2
maetugr 0:37f0c1e8fa66 3 #ifndef SERVO_H
maetugr 0:37f0c1e8fa66 4 #define SERVO_H
maetugr 0:37f0c1e8fa66 5
maetugr 0:37f0c1e8fa66 6 #include "mbed.h"
maetugr 0:37f0c1e8fa66 7
maetugr 0:37f0c1e8fa66 8 /** Class to control a servo on any pin, without using pwm
maetugr 0:37f0c1e8fa66 9 *
maetugr 0:37f0c1e8fa66 10 * Example:
maetugr 0:37f0c1e8fa66 11 * @code
maetugr 0:37f0c1e8fa66 12 * // Keep sweeping servo from left to right
maetugr 0:37f0c1e8fa66 13 * #include "mbed.h"
maetugr 0:37f0c1e8fa66 14 * #include "Servo.h"
maetugr 0:37f0c1e8fa66 15 *
maetugr 0:37f0c1e8fa66 16 * Servo Servo1(p20);
maetugr 0:37f0c1e8fa66 17 *
maetugr 0:37f0c1e8fa66 18 * Servo1.Enable(1500,20000);
maetugr 0:37f0c1e8fa66 19 *
maetugr 0:37f0c1e8fa66 20 * while(1) {
maetugr 0:37f0c1e8fa66 21 * for (int pos = 1000; pos < 2000; pos += 25) {
maetugr 0:37f0c1e8fa66 22 * Servo1.SetPosition(pos);
maetugr 0:37f0c1e8fa66 23 * wait_ms(20);
maetugr 0:37f0c1e8fa66 24 * }
maetugr 0:37f0c1e8fa66 25 * for (int pos = 2000; pos > 1000; pos -= 25) {
maetugr 0:37f0c1e8fa66 26 * Servo1.SetPosition(pos);
maetugr 0:37f0c1e8fa66 27 * wait_ms(20);
maetugr 0:37f0c1e8fa66 28 * }
maetugr 0:37f0c1e8fa66 29 * }
maetugr 0:37f0c1e8fa66 30 * @endcode
maetugr 0:37f0c1e8fa66 31 */
maetugr 0:37f0c1e8fa66 32
maetugr 0:37f0c1e8fa66 33 class Servo {
maetugr 0:37f0c1e8fa66 34
maetugr 0:37f0c1e8fa66 35 public:
maetugr 0:37f0c1e8fa66 36 /** Create a new Servo object on any mbed pin
maetugr 0:37f0c1e8fa66 37 *
maetugr 0:37f0c1e8fa66 38 * @param Pin Pin on mbed to connect servo to
maetugr 0:37f0c1e8fa66 39 */
maetugr 0:37f0c1e8fa66 40 Servo(PinName Pin, int frequency);
maetugr 0:37f0c1e8fa66 41 void SetFrequency(int frequency);
maetugr 0:37f0c1e8fa66 42
maetugr 0:37f0c1e8fa66 43 /** Change the position of the servo. Position in us
maetugr 0:37f0c1e8fa66 44 *
maetugr 0:37f0c1e8fa66 45 * @param NewPos The new value of the servos position (us)
maetugr 0:37f0c1e8fa66 46 */
maetugr 0:37f0c1e8fa66 47 void SetPosition(int NewPos);
maetugr 0:37f0c1e8fa66 48
maetugr 0:37f0c1e8fa66 49 /** Enable the servo. Without enabling the servo won't be running. Startposition and period both in us.
maetugr 0:37f0c1e8fa66 50 *
maetugr 0:37f0c1e8fa66 51 * @param StartPos The position of the servo to start (us)
maetugr 0:37f0c1e8fa66 52 * @param Period The time between every pulse. 20000 us = 50 Hz(standard) (us)
maetugr 0:37f0c1e8fa66 53 */
maetugr 0:37f0c1e8fa66 54 void Enable(int StartPos, int Period);
maetugr 0:37f0c1e8fa66 55
maetugr 0:37f0c1e8fa66 56 //Disable the servo. After disabling the servo won't get any signal anymore
maetugr 0:37f0c1e8fa66 57 void Disable();
maetugr 0:37f0c1e8fa66 58
maetugr 0:37f0c1e8fa66 59 //operator for confortable positioning
maetugr 0:37f0c1e8fa66 60 void operator=(int position);
maetugr 0:37f0c1e8fa66 61
maetugr 0:37f0c1e8fa66 62
maetugr 0:37f0c1e8fa66 63 private:
maetugr 0:37f0c1e8fa66 64 void StartPulse();
maetugr 0:37f0c1e8fa66 65 void EndPulse();
maetugr 0:37f0c1e8fa66 66
maetugr 0:37f0c1e8fa66 67 int Position;
maetugr 0:37f0c1e8fa66 68 DigitalOut ServoPin;
maetugr 0:37f0c1e8fa66 69 Ticker Pulse;
maetugr 0:37f0c1e8fa66 70 Timeout PulseStop;
maetugr 0:37f0c1e8fa66 71 };
maetugr 0:37f0c1e8fa66 72
maetugr 0:37f0c1e8fa66 73 #endif