Mearm colorsorting with web application

Dependencies:   TCS3200

Committer:
pierre11
Date:
Tue Jan 30 10:53:08 2018 +0000
Revision:
7:3b1ce80e424c
Parent:
5:36f1e4e1a427
MeARM +TCS3200

Who changed what in which revision?

UserRevisionLine numberNew contents of line
pierre11 5:36f1e4e1a427 1 /* mbed Servo Library without using PWM pins
pierre11 5:36f1e4e1a427 2 * Copyright (c) 2010 Jasper Denkers
pierre11 5:36f1e4e1a427 3 *
pierre11 5:36f1e4e1a427 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
pierre11 5:36f1e4e1a427 5 * of this software and associated documentation files (the "Software"), to deal
pierre11 5:36f1e4e1a427 6 * in the Software without restriction, including without limitation the rights
pierre11 5:36f1e4e1a427 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
pierre11 5:36f1e4e1a427 8 * copies of the Software, and to permit persons to whom the Software is
pierre11 5:36f1e4e1a427 9 * furnished to do so, subject to the following conditions:
pierre11 5:36f1e4e1a427 10 *
pierre11 5:36f1e4e1a427 11 * The above copyright notice and this permission notice shall be included in
pierre11 5:36f1e4e1a427 12 * all copies or substantial portions of the Software.
pierre11 5:36f1e4e1a427 13 *
pierre11 5:36f1e4e1a427 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
pierre11 5:36f1e4e1a427 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
pierre11 5:36f1e4e1a427 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
pierre11 5:36f1e4e1a427 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
pierre11 5:36f1e4e1a427 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
pierre11 5:36f1e4e1a427 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
pierre11 5:36f1e4e1a427 20 * THE SOFTWARE.
pierre11 5:36f1e4e1a427 21 */
pierre11 5:36f1e4e1a427 22
pierre11 5:36f1e4e1a427 23 #ifndef MBED_SERVO_H
pierre11 5:36f1e4e1a427 24 #define MBED_SERVO_H
pierre11 5:36f1e4e1a427 25
pierre11 5:36f1e4e1a427 26 #include "mbed.h"
pierre11 5:36f1e4e1a427 27
pierre11 5:36f1e4e1a427 28 /** Class to control a servo on any pin, without using pwm
pierre11 5:36f1e4e1a427 29 *
pierre11 5:36f1e4e1a427 30 * Example:
pierre11 5:36f1e4e1a427 31 * @code
pierre11 5:36f1e4e1a427 32 * // Keep sweeping servo from left to right
pierre11 5:36f1e4e1a427 33 * #include "mbed.h"
pierre11 5:36f1e4e1a427 34 * #include "Servo.h"
pierre11 5:36f1e4e1a427 35 *
pierre11 5:36f1e4e1a427 36 * Servo Servo1(p20);
pierre11 5:36f1e4e1a427 37 *
pierre11 5:36f1e4e1a427 38 * Servo1.Enable(1500,20000);
pierre11 5:36f1e4e1a427 39 *
pierre11 5:36f1e4e1a427 40 * while(1) {
pierre11 5:36f1e4e1a427 41 * for (int pos = 1000; pos < 2000; pos += 25) {
pierre11 5:36f1e4e1a427 42 * Servo1.SetPosition(pos);
pierre11 5:36f1e4e1a427 43 * wait_ms(20);
pierre11 5:36f1e4e1a427 44 * }
pierre11 5:36f1e4e1a427 45 * for (int pos = 2000; pos > 1000; pos -= 25) {
pierre11 5:36f1e4e1a427 46 * Servo1.SetPosition(pos);
pierre11 5:36f1e4e1a427 47 * wait_ms(20);
pierre11 5:36f1e4e1a427 48 * }
pierre11 5:36f1e4e1a427 49 * }
pierre11 5:36f1e4e1a427 50 * @endcode
pierre11 5:36f1e4e1a427 51 */
pierre11 5:36f1e4e1a427 52
pierre11 5:36f1e4e1a427 53 class Servo {
pierre11 5:36f1e4e1a427 54
pierre11 5:36f1e4e1a427 55 public:
pierre11 5:36f1e4e1a427 56 /** Create a new Servo object on any mbed pin
pierre11 5:36f1e4e1a427 57 *
pierre11 5:36f1e4e1a427 58 * @param Pin Pin on mbed to connect servo to
pierre11 5:36f1e4e1a427 59 */
pierre11 5:36f1e4e1a427 60 Servo(PinName Pin);
pierre11 5:36f1e4e1a427 61
pierre11 5:36f1e4e1a427 62 /** Change the position of the servo. Position in us
pierre11 5:36f1e4e1a427 63 *
pierre11 5:36f1e4e1a427 64 * @param NewPos The new value of the servos position (us)
pierre11 5:36f1e4e1a427 65 */
pierre11 5:36f1e4e1a427 66 void SetPosition(int NewPos);
pierre11 5:36f1e4e1a427 67
pierre11 5:36f1e4e1a427 68 /** Enable the servo. Without enabling the servo won't be running. Startposition and period both in us.
pierre11 5:36f1e4e1a427 69 *
pierre11 5:36f1e4e1a427 70 * @param StartPos The position of the servo to start (us)
pierre11 5:36f1e4e1a427 71 * @param Period The time between every pulse. 20000 us = 50 Hz(standard) (us)
pierre11 5:36f1e4e1a427 72 */
pierre11 5:36f1e4e1a427 73 void Enable(int StartPos, int Period);
pierre11 5:36f1e4e1a427 74
pierre11 5:36f1e4e1a427 75 /** Disable the servo. After disabling the servo won't get any signal anymore
pierre11 5:36f1e4e1a427 76 *
pierre11 5:36f1e4e1a427 77 */
pierre11 5:36f1e4e1a427 78 void Disable();
pierre11 5:36f1e4e1a427 79
pierre11 5:36f1e4e1a427 80 private:
pierre11 5:36f1e4e1a427 81 void StartPulse();
pierre11 5:36f1e4e1a427 82 void EndPulse();
pierre11 5:36f1e4e1a427 83
pierre11 5:36f1e4e1a427 84 int Position;
pierre11 5:36f1e4e1a427 85 DigitalOut ServoPin;
pierre11 5:36f1e4e1a427 86 Ticker Pulse;
pierre11 5:36f1e4e1a427 87 Timeout PulseStop;
pierre11 5:36f1e4e1a427 88 };
pierre11 5:36f1e4e1a427 89
pierre11 5:36f1e4e1a427 90 #endif