Skip to content

Commit 5065348

Browse files
committed
Add PowerOnButton example
1 parent 15cab54 commit 5065348

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
Test Power On button on LCD breakout board
3+
4+
Circuit:
5+
* Arduino Edge Control
6+
* Arduino Edge Control LCD brekout board
7+
*/
8+
9+
#include <Arduino_EdgeControl.h>
10+
11+
// Keep track of toggle-style press with an ISR
12+
volatile bool buttonPressed { false };
13+
bool ledStatus { false };
14+
15+
void setup()
16+
{
17+
Serial.begin(9600);
18+
19+
for (auto timeout = millis() + 2500l; !Serial && millis() < timeout; delay(250))
20+
;
21+
22+
Serial.println("Hello, Arduino Edge Control!");
23+
24+
Power.on(PWR_3V3);
25+
Power.on(PWR_VBAT);
26+
27+
Wire.begin();
28+
29+
delay(500);
30+
31+
Serial.print("IO Expander initializazion ");
32+
if (!Expander.begin()) {
33+
Serial.println("failed.");
34+
Serial.println("Please, be sure to enable gated 3V3 and 5V power rails");
35+
Serial.println("via Power.on(PWR_3V3) and Power.on(PWR_VBAT).");
36+
}
37+
Serial.println("succeeded.");
38+
39+
Expander.pinMode(EXP_LED1, OUTPUT);
40+
41+
pinMode(POWER_ON, INPUT);
42+
// ISR for button press detection
43+
attachInterrupt(
44+
digitalPinToInterrupt(POWER_ON), [] { buttonPressed = true; }, FALLING);
45+
46+
}
47+
48+
void loop()
49+
{
50+
if (buttonPressed == true) {
51+
buttonPressed = false;
52+
ledStatus = !ledStatus;
53+
Serial.print(millis());
54+
Serial.println(" Pressed");
55+
}
56+
57+
Expander.digitalWrite(EXP_LED1, ledStatus == true ? LOW : HIGH);
58+
}

0 commit comments

Comments
 (0)