Conversation
Notices
-
lamp (lamp@kitty.haus)'s status on Wednesday, 01-May-2024 10:42:51 JST lamp const int buttonPins[] = {2,3,4,5,6,7}; int lastBtnState[6] = {HIGH, HIGH, HIGH, HIGH, HIGH, HIGH}; unsigned long lastBtnTime[6]; void setup() { for (int i = 0; i < 6; i++) { pinMode(buttonPins[i], INPUT_PULLUP); } pinMode(LED_BUILTIN, OUTPUT); Serial.begin(9600); } void loop() { for (int i = 0; i < 6; i++) { int btnState = digitalRead(buttonPins[i]); if (btnState != lastBtnState[i]) { if (micros() - lastBtnTime[i] > 1000) { OnBtnStateChange(i, !btnState); } lastBtnState[i] = btnState; lastBtnTime[i] = micros(); } } } void OnBtnStateChange(int btn, bool pressed) { Serial.print(btn); Serial.println(pressed); digitalWrite(LED_BUILTIN, pressed); }