#include <Arduino.h>
const int BUTTON_COUNT = 5;
// Button GPIO pins
const int buttonPins[BUTTON_COUNT] = {
20, 8, 9, 10, 7
};
// LED GPIO pins
const int ledPins[BUTTON_COUNT] = {
6, 5, 4, 3, 2
};
void setup() {
Serial.begin(115200);
// Set up buttons
for (int i = 0; i < BUTTON_COUNT; i++) {
pinMode(buttonPins[i], INPUT_PULLUP);
}
// Set up LEDs
for (int i = 0; i < BUTTON_COUNT; i++) {
pinMode(ledPins[i], OUTPUT);
digitalWrite(ledPins[i], LOW);
}
Serial.println("ESP32-C3 Button Pad Ready!");
}
void loop() {
for (int i = 0; i < BUTTON_COUNT; i++) {
// INPUT_PULLUP means:
// LOW = button pressed
// HIGH = button released
if (digitalRead(buttonPins[i]) == LOW) {
digitalWrite(ledPins[i], HIGH);
Serial.print("Button ");
Serial.print(i + 1);
Serial.println(" pressed!");
} else {
digitalWrite(ledPins[i], LOW);
}
}
delay(10);
}
Loading
xiao-esp32-c3
xiao-esp32-c3