Electronics Project - Making a control panel that has push button and toggle switches with led lights on it

MrSalts

Joined Apr 2, 2020
2,767
I'm curious...

In post 33...

The choice to use nested "for" loops in "while" loops to poll for the button states, instead of "if" statements for example?

Is that a critical decision or just a preference?
Because nothing needs to happen until a button is pressed so just sitting in the while loop.

I might use if-statements if I had to check the buttons while still updating a multiplexed 7-seg display or similar intensive code was running.
 
Last edited:

MrSalts

Joined Apr 2, 2020
2,767
But it's not going to sit in either one of those while loops waiting for a button push, it sits in the main loop waiting for the button presses.
No, it does sit in those while loops waiting for a button press.
The pull-up resistor on each inputs keeps the pin value = 1 (High) until a button is pressed.
 

djsfantasi

Joined Apr 11, 2010
9,163
No, it does sit in those while loops waiting for a button press.
The pull-up resistor on each inputs keeps the pin value = 1 (High) until a button is pressed.
Aren’t those pull ups redundant? Arduino compatibles has pull up resistors built in. You just have to modify the input pinMode statements to activate them.

These lines of code…
Code:
  pinMode(10, INPUT); //start
  pinMode(12, INPUT); //reset
…should be…
Code:
  pinMode(10, INPUT_PULLUP); //start
  pinMode(12, INPUT_PULLUP); //reset
 

MrSalts

Joined Apr 2, 2020
2,767
Aren’t those pull ups redundant? Arduino compatibles has pull up resistors built in. You just have to modify the input pinMode statements to activate them.

These lines of code…
Code:
  pinMode(10, INPUT); //start
  pinMode(12, INPUT); //reset
…should be…
Code:
  pinMode(10, INPUT_PULLUP); //start
  pinMode(12, INPUT_PULLUP); //reset
They are but my simulator (used to make the animation and run the code) does not know how to do that.
 
Top