Useless Machine (Simultaneous loops ?)

Hi everybody

I am currently working on building a “useless machine” with 8 switches (in case you’re wondering what I’m talking about, you can check it out here - YouTube) and on my ARDUINO UNO card I don’t have enough analogic inputs to plug all the switches. Thus, I thought of using a multiplexer 4051.
I came up with the idea of coding it the following way: Put my selected inputs switch from 000 to 001 then 010 to 111… and loop it all over again endlessly until the output reaches the logic state ‘1’ which means that one of the switches has been switched ON so I just have to get my selected inputs’ values back.
But here’s the tricky part: In order to know if another switch has been set ON, I need my loop to keep going on all the time. That’s why I thought that I need simultaneous loops: First, the loop I’ve previously mentioned allowing to “detect” anytime a switch is set ON. Secondly, a “big” loop which is here to loop all the functions for the whole program to run well (for instance, when the 7th switch is turned ON at the moment the rod is in position “switch1” then FUNCTION_1 comes into play and lowers the rod down before FUNCTION_2 forces it to move towards position “switch7”). I think I’ve read somewhere across the forum that it’s not doable, but there must be a way to sort it out differently. It’d be really appreciated if some of you had an idea to work it out
Thanks in advance


Describe what all the pins (digital & analogue) will be doing as I can only think of 11 pins needed. You don’t need to use analogue pins for switches unless you have several connected to one pin via a resistor ladder.

That's why I thought that I need simultaneous loops:

No you don't. You need to scan all the switches first and put them in an array. Then you need to go through that array and decide if anything has changed since the last time through the loop. Then you need to carry on with the action of switching the switch off.

You do this with a software structure known as a state machine, an example of this is the blink without delay example in the IDE. There are a few web pages that describe this technique. My Robin2's several things at once

Hi, I don't think the OP realizes that if he is using ON/OFF switches he only needs digital inputs, and that analog inputs can be configured as digital and can use other digital pins.

Tom...... :)

Problem is humans are analog thinkers, even though we have digital synapses. (hmm very deep thinking for Saturday morning!!)

I don't have enough analogic inputs to plug all the switches.

For future reference the word is not "analogic inputs" but "analog inputs". I see it miss used like this often here.

Hi everybody, Just a little message to thank you for taking the time to make an answer to our post. Grumpy_Mike we are french students :) thanks for the correction ! If you are interested we will post a video of our useless machine and our code when it will be done !