-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added custom buttons (e.g. on PCF8574) added PCF8574 example long press and release method combo fix
- Loading branch information
Showing
4 changed files
with
116 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
#include <PCF8574.h> | ||
#include <debouncedButton.h> | ||
|
||
#define LED1 13 | ||
#define LED2 14 | ||
|
||
boolean led1State = HIGH; | ||
boolean led2State = HIGH; | ||
|
||
PCF8574 keypad(0x20); | ||
button button1(true, keypad.digitalInput.p0); | ||
button button2(true, keypad.digitalInput.p1); | ||
int mode = 0; | ||
char *modeStr[6] = {"press", "repeat", "long press", "release", "hold", "press"}; | ||
|
||
void setup() { | ||
pinMode(LED1, OUTPUT); | ||
pinMode(LED2, OUTPUT); | ||
digitalWrite(LED1, led1State); | ||
digitalWrite(LED2, led2State); | ||
keypad.pinMode(P0, INPUT_PULLUP); | ||
keypad.pinMode(P1, INPUT_PULLUP); | ||
keypad.begin(); | ||
Serial.begin(115200); | ||
} | ||
|
||
void loop() { | ||
keypad.digitalReadAll(); | ||
if (button1.press()) { | ||
mode++; | ||
Serial.println(modeStr[mode]); | ||
digitalWrite(LED1, HIGH); | ||
delay(100); | ||
digitalWrite(LED1, LOW); | ||
} | ||
switch (mode) { | ||
case 0: | ||
if (button2.press()) { | ||
Serial.println("button 2 press"); | ||
led2State = !led2State; | ||
digitalWrite(LED2, led2State); | ||
} | ||
break; | ||
case 1: | ||
if (button2.repeat()) { | ||
Serial.println("button 2 repeat"); | ||
led2State = !led2State; | ||
digitalWrite(LED2, led2State); | ||
} | ||
break; | ||
case 2: | ||
if (button2.longPress()) { | ||
Serial.println("button 2 long press"); | ||
led2State = !led2State; | ||
digitalWrite(LED2, led2State); | ||
} | ||
break; | ||
case 3: | ||
if (button2.release()) { | ||
Serial.println("button 2 release"); | ||
led2State = !led2State; | ||
digitalWrite(LED2, led2State); | ||
} | ||
break; | ||
case 4: | ||
if (button2.hold()) { | ||
Serial.println("button 2 hold"); | ||
led2State = true; | ||
} else { | ||
led2State = false; | ||
} | ||
digitalWrite(LED2, led2State); | ||
break; | ||
default: | ||
mode = 0; | ||
break; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters