File tree Expand file tree Collapse file tree 2 files changed +67
-0
lines changed
Expand file tree Collapse file tree 2 files changed +67
-0
lines changed Original file line number Diff line number Diff line change 1+ /* Copyright (c) 2022, Collab
2+ * All rights reserved
3+ */
4+
5+ #include " VibrationMotor.h"
6+
7+ VibrationMotor::VibrationMotor (
8+ int motor_pin,
9+ unsigned int period
10+ ) {
11+ _motorPin = motor_pin;
12+ _period = period;
13+ }
14+
15+ void VibrationMotor::begin () {
16+ pinMode (_motorPin, OUTPUT);
17+ }
18+
19+ void VibrationMotor::loop () {
20+ if (_enabled) {
21+ if ((millis () - _enablePoint) >= _period) {
22+ disable ();
23+ }
24+ }
25+ }
26+
27+ void VibrationMotor::enable () {
28+ _enabled = true ;
29+ _enablePoint = millis ();
30+
31+ digitalWrite (_motorPin, HIGH);
32+ }
33+
34+ void VibrationMotor::disable () {
35+ _enabled = false ;
36+
37+ digitalWrite (_motorPin, LOW);
38+ }
Original file line number Diff line number Diff line change 1+ /* Copyright (c) 2022, Collab
2+ * All rights reserved
3+ */
4+ #ifndef VibrationMotor_h
5+ #define VibrationMotor_h
6+
7+ #include < Arduino.h>
8+
9+ class VibrationMotor
10+ {
11+ public:
12+ VibrationMotor (
13+ int motor_pin,
14+ unsigned int period = 250
15+ );
16+ void begin ();
17+ void loop ();
18+ void enable ();
19+ void disable ();
20+
21+ private:
22+ int _motorPin;
23+ unsigned int _period;
24+ unsigned int _enablePoint;
25+
26+ bool _enabled = false ;
27+ };
28+
29+ #endif
You can’t perform that action at this time.
0 commit comments