File tree Expand file tree Collapse file tree 6 files changed +167
-0
lines changed Expand file tree Collapse file tree 6 files changed +167
-0
lines changed Original file line number Diff line number Diff line change
1
+ /*
2
+ Button_PCF8574.cpp - Control PCF8574 connected button.
3
+ */
4
+
5
+ #include " Button_PCF8574.h"
6
+
7
+ Button_PCF8574::Button_PCF8574 (
8
+ int btn_pin,
9
+ MultiPlexer_PCF8574* pcf,
10
+ Method callback
11
+ ) {
12
+ _btnPin = btn_pin;
13
+ _pcf = pcf;
14
+ _callback = callback;
15
+ _lastBtnState = LOW;
16
+ }
17
+
18
+ void Button_PCF8574::begin () {
19
+ }
20
+
21
+ void Button_PCF8574::loop () {
22
+ read ();
23
+ }
24
+
25
+ void Button_PCF8574::read () {
26
+ /*
27
+ int buttonReading = _mcp->getPin(_btnPin, _port);
28
+
29
+ // if the switch changed, due to noise or pressing
30
+ if (buttonReading != _lastBtnState) {
31
+ // reset the debouncing timer
32
+ _lastDebounceTime = millis();
33
+ }
34
+ if ((millis() - _lastDebounceTime) > _debounceDelay) {
35
+ // if the button state has changed
36
+ if (buttonReading != _currentBtnState) {
37
+ _currentBtnState = buttonReading;
38
+
39
+ // only toggle if the new button state is HIGH
40
+ if (_currentBtnState == HIGH) {
41
+ _callback.callbackIntArg(_btnPin);
42
+ }
43
+ }
44
+ }
45
+ // save the switch reading
46
+ _lastBtnState = buttonReading;
47
+ */
48
+ }
Original file line number Diff line number Diff line change
1
+ /*
2
+ Button_PCF8574.cpp - Control PCF8574 connected button.
3
+ */
4
+ #ifndef Button_PCF8574_h
5
+ #define Button_PCF8574_h
6
+
7
+ #include < Arduino.h>
8
+ #include < Method.h>
9
+ #include < MultiPlexer_PCF8574.h>
10
+
11
+ class Button_PCF8574
12
+ {
13
+ public:
14
+ Button_PCF8574 (
15
+ int btn_pin,
16
+ MultiPlexer_PCF8574* pcf,
17
+ Method callback
18
+ );
19
+ void loop ();
20
+ void begin ();
21
+ void read ();
22
+
23
+ private:
24
+ int _btnPin;
25
+ int _currentBtnState;
26
+ int _lastBtnState;
27
+ Method _callback;
28
+ MultiPlexer_PCF8574* _pcf;
29
+ unsigned long _lastDebounceTime = 0 ;
30
+ unsigned long _debounceDelay = 5 ;
31
+ };
32
+
33
+ #endif
Original file line number Diff line number Diff line change
1
+ /*
2
+ LED_PCF8574.h - Control LED light using PCF8574 multiplexer.
3
+ */
4
+
5
+ #include " LED_PCF8574.h"
6
+
7
+ LED_PCF8574::LED_PCF8574 (
8
+ int pin,
9
+ MultiPlexer_PCF8574* pcf,
10
+ int led_state
11
+ ) {
12
+ _pin = pin;
13
+ _pcf = pcf;
14
+ state = led_state;
15
+ }
16
+
17
+ void LED_PCF8574::begin () {
18
+ _pcf->pinMode (_pin, OUTPUT);
19
+ }
20
+
21
+ void LED_PCF8574::loop () {
22
+ }
23
+
24
+ void LED_PCF8574::update () {
25
+ _pcf->digitalWrite (_pin, state);
26
+ }
27
+
28
+ void LED_PCF8574::enable () {
29
+ state = HIGH;
30
+ update ();
31
+ }
32
+
33
+ void LED_PCF8574::disable () {
34
+ state = LOW;
35
+ update ();
36
+ }
37
+
38
+ void LED_PCF8574::toggle () {
39
+ state = !state;
40
+ update ();
41
+ }
Original file line number Diff line number Diff line change
1
+ /*
2
+ LED_PCF8574.h - Control LED light using PCF8574 multiplexer.
3
+ */
4
+ #ifndef LED_PCF8574_h
5
+ #define LED_PCF8574_h
6
+
7
+ #include " Arduino.h"
8
+ #include < MultiPlexer_PCF8574.h>
9
+
10
+ class LED_PCF8574
11
+ {
12
+ public:
13
+ LED_PCF8574 (
14
+ int pin,
15
+ MultiPlexer_PCF8574* pcf,
16
+ int led_state = LOW
17
+ );
18
+ int state;
19
+ void begin ();
20
+ void loop ();
21
+ void enable ();
22
+ void disable ();
23
+ void toggle ();
24
+
25
+ private:
26
+ void update ();
27
+
28
+ int _pin;
29
+ MultiPlexer_PCF8574* _pcf;
30
+ };
31
+
32
+ #endif
Original file line number Diff line number Diff line change @@ -10,6 +10,8 @@ MultiPlexer_PCF8574::MultiPlexer_PCF8574(uint8_t address) {
10
10
11
11
void MultiPlexer_PCF8574::begin () {
12
12
Serial.print (" Initializing PCF8574... " );
13
+
14
+ /*
13
15
// inputs
14
16
int i = 0;
15
17
for (i = 0; i<4; i++) {
@@ -19,6 +21,7 @@ void MultiPlexer_PCF8574::begin() {
19
21
for (i=4; i<8; i++) {
20
22
_expander->pinMode(i, OUTPUT, LOW);
21
23
}
24
+ */
22
25
23
26
if (_expander->begin ()) {
24
27
Serial.println (" OK" );
@@ -29,3 +32,11 @@ void MultiPlexer_PCF8574::begin() {
29
32
30
33
void MultiPlexer_PCF8574::loop () {
31
34
}
35
+
36
+ void MultiPlexer_PCF8574::pinMode (uint8_t pin, uint8_t mode, uint8_t initialValue) {
37
+ _expander->pinMode (pin, mode, initialValue);
38
+ }
39
+
40
+ void MultiPlexer_PCF8574::digitalWrite (uint8_t pin, uint8_t value) {
41
+ _expander->digitalWrite (pin, value);
42
+ }
Original file line number Diff line number Diff line change @@ -14,6 +14,8 @@ class MultiPlexer_PCF8574
14
14
MultiPlexer_PCF8574 (uint8_t address);
15
15
void begin ();
16
16
void loop ();
17
+ void pinMode (uint8_t pin, uint8_t mode, uint8_t initialValue = HIGH);
18
+ void digitalWrite (uint8_t pin, uint8_t value);
17
19
18
20
private:
19
21
PCF8574* _expander;
You can’t perform that action at this time.
0 commit comments