Update nach erstem Aufbau in der Stadtbib
This commit is contained in:
1 parent
b758784969
commit
75ce71f4df
8 files changed
+284
No files matched your search
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
- Wiring: connect each button between its pin and GND — no resistors needed.
|
||||
- Open the Serial Monitor at 9600 baud in the Arduino IDE to see the output.
|
||||
*/
|
||||
|
||||
const int NUM_BUTTONS = 12;
|
||||
const int BUTTON_PINS[NUM_BUTTONS] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13};
|
||||
|
||||
bool lastState[NUM_BUTTONS];
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
for (int i = 0; i < NUM_BUTTONS; i++) {
|
||||
pinMode(BUTTON_PINS[i], INPUT_PULLUP);
|
||||
lastState[i] = HIGH;
|
||||
}
|
||||
Serial.println("Button test ready. Press a button!");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
for (int i = 0; i < NUM_BUTTONS; i++) {
|
||||
bool currentState = digitalRead(BUTTON_PINS[i]);
|
||||
|
||||
if (currentState == LOW && lastState[i] == HIGH) {
|
||||
Serial.print("Button ");
|
||||
Serial.print(i + 1);
|
||||
Serial.print(" pressed! (pin D");
|
||||
Serial.print(BUTTON_PINS[i]);
|
||||
Serial.println(")");
|
||||
}
|
||||
|
||||
lastState[i] = currentState;
|
||||
}
|
||||
delay(50); // simple debounce
|
||||
}
|
||||
Reference in new issue
Block a user