acid-drop- Hacking the planet from a LilyGo T-Deck using custom firmware |
git clone git://git.acid.vegas/acid-drop.git |
Log | Files | Refs | Archive | README | LICENSE |
HelloButton.ino (1206B)
1 /* 2 * A demo of a simplest AceButton that has a visible effect. One button is 3 * connected to the digital pin BUTTON_PIN. It uses the internal pull-up 4 * resistor (INPUT_PULLUP). Pressing the button turns on the built-in LED. 5 * Releasing the button turns off the LED. 6 */ 7 8 #include <AceButton.h> 9 10 using namespace ace_button; 11 12 // Some ESP32 boards have multiple builtin LEDs so don't define LED_BUILTIN. 13 #if defined(ESP32) 14 const int LED_PIN = 2; 15 #else 16 const int LED_PIN = LED_BUILTIN; 17 #endif 18 19 const int BUTTON_PIN = 2; 20 const int LED_ON = HIGH; 21 const int LED_OFF = LOW; 22 23 AceButton button(BUTTON_PIN); 24 25 void handleEvent(AceButton*, uint8_t, uint8_t); 26 27 void setup() { 28 delay(2000); 29 30 #if defined(ARDUINO_AVR_LEONARDO) 31 RXLED0; // LED off 32 TXLED0; // LED off 33 #endif 34 35 pinMode(LED_PIN, OUTPUT); 36 pinMode(BUTTON_PIN, INPUT_PULLUP); 37 button.setEventHandler(handleEvent); 38 } 39 40 void loop() { 41 button.check(); 42 } 43 44 void handleEvent(AceButton* /* button */, uint8_t eventType, 45 uint8_t /* buttonState */) { 46 switch (eventType) { 47 case AceButton::kEventPressed: 48 digitalWrite(LED_PIN, LED_ON); 49 break; 50 case AceButton::kEventReleased: 51 digitalWrite(LED_PIN, LED_OFF); 52 break; 53 } 54 }