ไลบารีใช้ในการจัดการขา IO ของ Arduino ให้เป็น Switch Input
This library allows you to use GPIO pins of Arduino, ESP32, and ESP8266 (including touch pins for ESP32) as buttons or switches. It is easy to use.
Support the following Event-Driven -Press -Release -Click -DoubleClick -Hold (long press) -LongHold (more than LongPress)
picture from // Change Arduino editor font to "Courier New" for specify correct ESP32 image below. // 1.Click the link at the line following File > Preferences > More preferences can be edited directly in the file. // This will open the .Arduino15 (or something like that) folder. // 2.Exit the Arduino IDE // 3.Open the file preferences.txt in a text editor. // 4.Search for the line that starts with "editor.font". // 5.Change the first word following the equals sign on that line to the "Courier New". // like this "editor.font=Courier New,plain,11" // 6.Save the file. // 7.Start the Arduino IDE. The editor should now be using the font you chose. // // // // ┌─────────────────────────────┐ // │ ┌───┐ ┌───┐ ┌───┬───┐ │ // │ │ │ │ │ │ │ │ │ // │ │ └───┘ └───┘ │ │ │ // │ │ │ │ // │┌───────────────────────────┐│ // GND 1-▓┤│ º │├▓-38 GND // VCC 2-▓┤│ ░├▓-37 GPIO23 // ! EN 3-▓┤│ ░├▓-36 GPIO22 SCL // ADC_H ADC1_0 SensVP GPI36 4-▓┤│ ░├▓-35 GPIO1 TX0 CLK03 // ADC_H ADC1_3 SensVN GPI39 5-▓┤│ ░├▓-34 GPIO3 RX0 CLK02 // ADC1_6 GPI34 6-▓┤│ ░├▓-33 GPIO21 SDA // ADC1_7 GPI35 7-▓┤│ ESP32 ░├▓-32 GPIO20 // XTAL32 ADC1_4 T9 GPO32 8-▓┤░ ░├▓-31 GPIO19 // XTAL32 ADC1_5 T8 GPO33 9-▓┤░ ░├▓-30 GPIO18 // ADC2_8 DAC_1 GPIO25 10-▓┤░ ░├▓-29 GPIO5 // ADC2_9 DAC_2 GPIO26 11-▓┤░ ░├▓-28 GPIO17 TX1 // ADC2_7 T7 GPIO27 12-▓┤░ ░├▓-27 GPIO16 RX1 // ADC2_6 T6 GPIO14 13-▓┤░ ░├▓-26 GPIO4 T0 ADC2_0 // ADC2_5 T5 GPIO12 14-▓┤░──────░░░░░░░░░░░░░░░░░────░├▓-25 GPIO0 T1 ADC2_1 CLK01 // └─────▓─▓─▓─▓─▓─▓─▓─▓─▓─▓─────┘ // GND 15────────┘ │ │ │ │ │ │ │ │ └────────24 GPIO2 T2 ADC2_2 // ADC2_4 T4 GPIO13 16──────────┘ │ │ │ │ │ │ └──────────23 GPIO15 T3 ADC2_3 // SD_D2 GPIO9 17────────────┘ │ │ │ │ └────────────22 GPIO8 SD_D1 // SD_D3 GPIO10 18──────────────┘ │ │ └──────────────21 GPIO7 SD_D0 // SD_CMD GPIO11 19────────────────┘ └────────────────20 GPIO6 SD_CLK // // // // ░ PWM Pin // 1-38 Physical pin on package // // Absolute MAX per pin 12mA, recommended 6mA // VCC = 3.3V // // // //this library tested and Its work! for Arduino, ESP32, ESP8266 #include <Button.h> //declare button obj use pin 2, DIO as default pinType and HIGH Active state //the following ESP32 pins work with INPUT_PULLUP: 14, 16, 17, 18, 19, 21, 22, 23 Button button(2); //same as below //Button button(2,DIO,LOW); void press(int sender) { Serial.println("Press pin " + String(sender)); } void release(int sender) { Serial.println("Release pin " + String(sender)); } void click(int sender) { Serial.println("Click pin " + String(sender)); } void doubleClick(int sender) { Serial.println("Double Click pin " + String(sender)); } void hold(int sender) { Serial.println("Hold pin " + String(sender)); } void longHold(int sender) { Serial.println("Long Hold pin " + String(sender)); } void setup() { // put your setup code here, to run once: Serial.begin(115200); //set callback function for Button #if defined(ESP32) || defined(ESP8266) button.eventPress((void*)press); button.eventRelease((void*)release); button.eventClick((void*)click); button.eventDoubleClick((void*)doubleClick); button.eventHold((void*)hold); button.eventLongHold((void*)longHold); #else button.eventPress(press); button.eventRelease(release); button.eventClick(click); button.eventDoubleClick(doubleClick); button.eventHold(hold); button.eventLongHold(longHold); #endif /*set time for event with milliseconds button.setDoubleClickTime(250); button.setHoldTime(2000); button.setLongHoldTime(5000); */ } void loop() { /*handle button action*/ button.handleButton(); // put your main code here, to run repeatedly: }
-
Notifications
You must be signed in to change notification settings - Fork 0
cchian/Button
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
About
ไลบารีใช้ในการจัดการขา IO ของ Arduino ให้เป็น Switch Input
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published