New answers tagged

3

When you want to perform actions in response to button presses, you should take care of reacting to the signal edges rather than levels. In other words, you perform the action only when the signal changes from LOW to HIGH, not every time you see it HIGH. You should also read about button bounce, and either implement your own debouncing or use an existing ...


1

Michael has already given you some excellent advice on how to clean up your code. Your switch statement does not make much sense. You're switching based on an out-of-range index into an array of constants. Once you've read the states of all your buttons as outlined by Michael, your loop needs to decide what to do about the state of each switch. Is this a ...


1

Next time align your code with ctrl-K (after selecting). And yes, you can heavily optimize your code (for maintainability) using arrays: Instead of const int buttonPin1 = 2; const int buttonPin2 = 3; const int buttonPin3 = 4; const int buttonPin4 = 5; const int buttonPin5 = 6; use const int buttonPins[] = { 2, 3, 4, 5, 6 }; In software engineering it's ...


Top 50 recent answers are included