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 bool isActive() { return attached(); }
58
60 virtual void setIsActive(bool active);
61
63 virtual void activate() { setIsActive(true); }
64
66 virtual void deactivate() { setIsActive(false); }
67
68protected:
69 virtual void begin();
70
71 // Servo pin (must be PWM).
72 uint8_t _pin;
73};
74
76class ServoOut : public AbstractServoOut {
77public:
83
89 virtual float putAngle(float angle);
90
92 virtual float getAngle();
93};
94
97public:
103
105 virtual void stop();
106
108 virtual void invert();
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:63
uint8_t pin() const
Returns the pin this servomotor is attached to.
Definition PqServo.h:54
virtual void setIsActive(bool active)
Activates or deactivates the servomotor.
Definition PqServo.cpp:40
virtual bool isActive()
Returns true if the servomotor is active.
Definition PqServo.h:57
virtual void deactivate()
Deactivates the servomotor.
Definition PqServo.h:66
An analog analog source that contains a value constrained to a finite range (typically in [0,...
Definition PqCore.h:482
Continuous servo-motor.
Definition PqServo.h:96
virtual void invert()
Sends servomotor in opposite direction.
Definition PqServo.cpp:78
virtual void stop()
Stops the servo-motor.
Definition PqServo.cpp:72
The main Plaquette static class containing all the units.
Definition PqCore.h:63
static Engine & primary()
Returns the main instance of Plaquette.
Definition PqCore.cpp:30
Standard servo-motor (angular).
Definition PqServo.h:76
virtual float putAngle(float angle)
Sets the servomotor position to a specific angle between 0 and 180 degrees.
Definition PqServo.cpp:55
virtual float getAngle()
Return the current angular angle in [0, 180].
Definition PqServo.cpp:61
Engine * engine() const
Returns the engine that owns this unit.
Definition PqCore.h:420