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