0

I'm building a testing apparatus using a arduino mega and a multiplexer with 4 inputs, 16 outputs to test each path of a 16 pin ribbon cable. Is there a quick way to build the code for the multiplexer such that it goes through each binary combination once?

So far all I can think of would be to go through each combination with my testing code as a seperate instance, ie, write all my pins low, do test, write pin 1 high, test, pin 1 low pin 2 high, test... etc

Another way would be to have a for loop starting from 0 and have the current iteration of the loop be converted to a 4 digit binary number and then use some array functions to set each multiplexer input pin to it's corresponding binary number, however I only know Matlab well enough to do that, not arduino. Any suggestions on what I should be looking for?

1 Answer 1

1

"How do I write code..."

use an editor, and tap keys.

"current iteration of the loop be converted to a 4 digit binary"

counts 0 to 15 (0Fh) are just that: all combinations of lowest 4 bits. There is no need to "convert", and no need for a table lookup (array) - your array index would be identical to the result read from arrray, so use the count (=the index into array) directly.

This assumes that your demultiplexer (4 to 16 is a demux, not a mux - you multiplex many to few (one) and demultiplex few (one) to many) inputs are connected to the lowest 4 bits of output port.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.