Plaquette
 
Loading...
Searching...
No Matches
PqServo.h
1/*
2 * PqServo.h
3 *
4 * (c) 2017 Sofian Audry :: info(@)sofianaudry(.)com
5 *
6 * This program is free software: you can redistribute it and/|| modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, ||
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY || FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19#ifndef PQ_SERVO_H_
20#define PQ_SERVO_H_
21
22#ifndef PQ_ARCH_SUPPORTS_SERVO
23#if (defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_SAM) || \
24 defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_STM32F4) || defined(ARDUINO_ARCH_NRF52))
25 #define PQ_ARCH_SUPPORTS_SERVO 1
26#else
27 #define PQ_ARCH_SUPPORTS_SERVO 0
28#endif
29#endif
30
31#if PQ_ARCH_SUPPORTS_SERVO
32
33#include "PqCore.h"
34#include <Servo.h>
35
36namespace pq {
37
39class AbstractServoOut : public AnalogSource, public Servo {
40protected:
42
43public:
44 virtual ~AbstractServoOut();
45
51 virtual float put(float value);
52
54 uint8_t pin() const { return _pin; }
55
57 virtual void activate() { attach(_pin); }
58
60 virtual void deactivate() { detach(); }
61
63 virtual bool isActive() { return attached(); }
64
65protected:
66 virtual void begin();
67
68 // Servo pin (must be PWM).
69 uint8_t _pin;
70};
71
73class ServoOut : public AbstractServoOut {
74public:
80
86 virtual float putAngle(float angle);
87
89 virtual float getAngle();
90
92 virtual void center() { put(0.5); }
93};
94
97public:
103
105 virtual void stop();
106
108 virtual void reverse();
109
110protected:
111 virtual void begin();
112};
113
114} // namespace pq
115
116#endif
117#endif
Servo-motor absract object.
Definition PqServo.h:39
virtual float put(float value)
Pushes value into the unit.
Definition PqServo.cpp:32
virtual void activate()
Activates the servomotor (default).
Definition PqServo.h:57
uint8_t pin() const
Returns the pin this servomotor is attached to.
Definition PqServo.h:54
virtual bool isActive()
Returns true if the servomotor is active.
Definition PqServo.h:63
virtual void deactivate()
Deactivates the servomotor.
Definition PqServo.h:60
An analog analog source that contains a value constrained to a finite range (typically in [0,...
Definition PqCore.h:444
Continuous servo-motor.
Definition PqServo.h:96
virtual void reverse()
Sends servo-motor in reverse mode.
Definition PqServo.cpp:69
virtual void stop()
Stops the servo-motor.
Definition PqServo.cpp:63
The main Plaquette static class containing all the units.
Definition PqCore.h:60
static Engine & primary()
Returns the main instance of Plaquette.
Definition PqCore.cpp:31
Standard servo-motor (angular).
Definition PqServo.h:73
virtual float putAngle(float angle)
Sets the servomotor position to a specific angle between 0 and 180 degrees.
Definition PqServo.cpp:46
virtual float getAngle()
Return the current angular angle in [0, 180].
Definition PqServo.cpp:52
virtual void center()
Re-centers the servo-motor.
Definition PqServo.h:92
Engine * engine() const
Returns the engine that owns this unit.
Definition PqCore.h:382