I think this question may be as much a mathematical question as it is an Arduino programming question.
I’m using a Leonardo and have the need to report several hundred data points using optocouplers. Rather than using a single optocoupler per data point, I realized that I could do this using 11 otptocouplers along with a “digital-code” and thereby be able to report up to 1024 unique conditions.
Here is the layout:
The 11 LEDs: A, B, C, D, E, F, G, H, I, J, K
These correspond to the following numbers:
As an example, let’s say that the number 665 represented a condition that needed to be reported. So to report condition 665, the LEDs of optocouplers B,D,G,H,K would be written HIGH, and the remaining optocouplers LEDs would be written LOW. Here are a couple of examples showing how this works:
Unfortunately, my math skills have been under-used for a couple of decades. Is there an equation, whereby given the input of 665, the derivation of the corresponding LEDs could be calculated automatically? I’ve been looking at geometric series, but thus far the equations I have found don’t seem to be relevant for this objective. While the 1,2,4,8,16 etc is a geometric series, I’m not sure what the objective outlined above would be called.
From an Arduino code perspective, how would a function be designed so that the desired HIGH/LOW state of the 11 optocouplers LEDs could be passed to the function?
Project Note: Optocouplers have to be used because the circuit of the Arduino used for monitoring and the circuit of the other equipment must be kept separate. Serial communication is not an option.