EveryCircuit
Powering up...
Circuit
Public
Private
Unlisted
Save

Seven Buttons with Three Logics

@nforystek
3 months ago
https://everycircuit.com/circuit/6148761842352128
I use this method with an Arduino when I only have so many digital pins (three) and want more buttons (seven in this case). Where as the LED's represent the logic inputs to the Arduino, Inside the software source you would preform checks for multiple logic patterns of simultaneous inputs at a single instant and know the corresponding button. Here is a wokwi version: https://wokwi.com/projects/454438811343692801 Code: /* seven buttons with three pins circuit at https://everycircuit.com/circuit/6148761842352128 connect the positive of the LED's in the circuit to these pins below and the negative to ground, also the 5v substituted to the Arduino 5v and GND */ #define pin1 2 #define pin2 3 #define pin3 4 void setup() { pinMode(pin1, INPUT); pinMode(pin2, INPUT); pinMode(pin3, INPUT); Serial.begin(115200); } void loop() { byte btnBits=digitalRead(pin1)?1:0; btnBits+=digitalRead(pin2)?2:0; btnBits+=digitalRead(pin1)?4:0; static bool toggle=false; if ((btnBits!=0)&&(!toggle)) { toggle=true; Serial.print("Button "); Serial.print(btnBits); Serial.println(" Pressed"); } else toggle=false; } // - nforystek
Comments
Post