feat: 全量同步 254 个常用的 Arduino 扩展库文件

This commit is contained in:
yczpf2019
2026-01-24 16:05:38 +08:00
parent c665ba662b
commit 397b9a23a3
6878 changed files with 2732224 additions and 1 deletions

View File

@@ -0,0 +1,50 @@
/////////////////////////////////////////////////////////////////
#include "Button2.h"
/////////////////////////////////////////////////////////////////
#define BUTTON_PIN 2
/////////////////////////////////////////////////////////////////
Button2 button = Button2(BUTTON_PIN);
/////////////////////////////////////////////////////////////////
void setup() {
Serial.begin(9600);
while (!Serial) {
delay(20);
}
Serial.println("\n\nLongpress Handler Demo");
button.setLongClickHandler(longpress);
}
/////////////////////////////////////////////////////////////////
void loop() {
button.loop();
}
/////////////////////////////////////////////////////////////////
void longpress(Button2& btn) {
unsigned int time = btn.wasPressedFor();
Serial.print("You clicked ");
if (time > 1500) {
Serial.print("a really really long time.");
} else if (time > 1000) {
Serial.print("a really long time.");
} else if (time > 500) {
Serial.print("a long time.");
} else {
Serial.print("long.");
}
Serial.print(" (");
Serial.print(time);
Serial.println(" ms)");
}
/////////////////////////////////////////////////////////////////

View File

@@ -0,0 +1,53 @@
/////////////////////////////////////////////////////////////////
#include "Button2.h"
/////////////////////////////////////////////////////////////////
#define BUTTON_PIN 2
/////////////////////////////////////////////////////////////////
Button2 button = Button2(BUTTON_PIN);
/////////////////////////////////////////////////////////////////
void setup() {
Serial.begin(9600);
delay(50);
Serial.println("\n\nMulti Handler Demo");
button.setClickHandler(handler);
button.setLongClickHandler(handler);
button.setDoubleClickHandler(handler);
button.setTripleClickHandler(handler);
}
/////////////////////////////////////////////////////////////////
void loop() {
button.loop();
}
/////////////////////////////////////////////////////////////////
void handler(Button2& btn) {
switch (btn.getClickType()) {
case SINGLE_CLICK:
break;
case DOUBLE_CLICK:
Serial.print("double ");
break;
case TRIPLE_CLICK:
Serial.print("triple ");
break;
case LONG_CLICK:
Serial.print("long");
break;
}
Serial.print("click");
Serial.print(" (");
Serial.print(btn.getNumberOfClicks());
Serial.println(")");
}
/////////////////////////////////////////////////////////////////

View File

@@ -0,0 +1,43 @@
/////////////////////////////////////////////////////////////////
#include "Button2.h"
/////////////////////////////////////////////////////////////////
#define BUTTON_A_PIN 2
#define BUTTON_B_PIN 0
/////////////////////////////////////////////////////////////////
Button2 buttonA = Button2(BUTTON_A_PIN);
Button2 buttonB = Button2(BUTTON_B_PIN);
/////////////////////////////////////////////////////////////////
void setup() {
Serial.begin(9600);
delay(50);
Serial.println("\n\nMultiple Buttons Demo");
buttonA.setClickHandler(click);
buttonB.setClickHandler(click);
}
/////////////////////////////////////////////////////////////////
void loop() {
buttonA.loop();
buttonB.loop();
}
/////////////////////////////////////////////////////////////////
void click(Button2& btn) {
if (btn == buttonA) {
Serial.println("A clicked");
} else if (btn == buttonB) {
Serial.println("B clicked");
}
}
/////////////////////////////////////////////////////////////////

View File

@@ -0,0 +1,77 @@
/////////////////////////////////////////////////////////////////
#include "Button2.h"
/////////////////////////////////////////////////////////////////
#define BUTTON_PIN 36
/////////////////////////////////////////////////////////////////
Button2 button = Button2(BUTTON_PIN);
/////////////////////////////////////////////////////////////////
void setup() {
Serial.begin(9600);
delay(50);
Serial.println("\n\nButton Demo");
// button.setLongClickTime(1000);
// button.setDoubleClickTime(400);
Serial.println(" Longpress Time: " + String(button.getLongClickTime()) + "ms");
Serial.println(" DoubleClick Time: " + String(button.getDoubleClickTime()) + "ms");
// button.setChangedHandler(changed);
// button.setPressedHandler(pressed);
button.setReleasedHandler(released);
// button.setTapHandler(tap);
button.setClickHandler(click);
button.setLongClickDetectedHandler(longClickDetected);
button.setLongClickHandler(longClick);
button.setDoubleClickHandler(doubleClick);
button.setTripleClickHandler(tripleClick);
}
/////////////////////////////////////////////////////////////////
void loop() {
button.loop();
}
/////////////////////////////////////////////////////////////////
void pressed(Button2& btn) {
Serial.println("pressed");
}
void released(Button2& btn) {
Serial.print("released: ");
Serial.println(btn.wasPressedFor());
}
void changed(Button2& btn) {
Serial.println("changed");
}
void click(Button2& btn) {
Serial.println("click\n");
}
void longClickDetected(Button2& btn) {
Serial.println("long click detected\n");
}
void longClick(Button2& btn) {
Serial.println("long click\n");
}
void doubleClick(Button2& btn) {
Serial.println("double click\n");
}
void tripleClick(Button2& btn) {
Serial.println("triple click\n");
}
void tap(Button2& btn) {
Serial.println("tap");
}
/////////////////////////////////////////////////////////////////

View File

@@ -0,0 +1,50 @@
/////////////////////////////////////////////////////////////////
#include "Button2.h"
/////////////////////////////////////////////////////////////////
#define BUTTON_PIN 2
/////////////////////////////////////////////////////////////////
Button2 button = Button2(BUTTON_PIN);
/////////////////////////////////////////////////////////////////
void setup() {
Serial.begin(9600);
delay(50);
Serial.println("\n\nButton Demo");
button.setChangedHandler(changed);
//button.setPressedHandler(pressed);
//button.setReleasedHandler(released);
// captures any type of click, longpress or shortpress
button.setTapHandler(tap);
}
/////////////////////////////////////////////////////////////////
void loop() {
button.loop();
}
/////////////////////////////////////////////////////////////////
void pressed(Button2& btn) {
Serial.println("pressed");
}
void released(Button2& btn) {
Serial.print("released: ");
Serial.println(btn.wasPressedFor());
}
void changed(Button2& btn) {
Serial.println("changed");
}
void tap(Button2& btn) {
Serial.println("tap");
}
/////////////////////////////////////////////////////////////////