Is it possible to write an a2d convertor to use 1 pad for 2 switches?

Context is a 3 button setup (to emulate dual phase saber) on a regiis (customized as a princess saber for my daughter) with master chassis using the optional second crystal instead of the rotating plasma gate. Im using the 12mm 2 button switch (brass) from khal/the saber armory to get the 3rd physical button.

The connector between the two parts of the chasis has 6 pins, i’d need 7 to wire the 3rd button normally. But i saw this trick

https://analog10.com/posts/rotary_encoder_analog_input.html?fbclid=IwY2xjawJiGz9leHRuA2FlbQIxMQABHq9jurR9nMopOYBlrAIzTn59KYPERdU-3hXCXrQvXoyGrZmfHGFcEjSMMZQK_aem_oiHWn0mplLp96asnias2HA

And the analogous circuit is pretty simple. We’d need in parallel 2 sets each of a resistor and switch, with different resistances. If both switches are pressed the combined resistance is 1/(1/R1+1/R2). Meaning we can have 3 different resistances (4 being infinite if neither switch is pressed).

I don’t know the operating principles of the proffieboard… is a constant current supplied whhich would mean 3 different voltage differences that could be measured, or a constant voltage difference which woyld mean 3 different currents, does the board only support current/no current measurements… it’s been 30.years since i took a circuits class, and probably a decade since i designed a circuit (areospace/mechanical focusing on simulation/algoritms/applied math, C++ is my strongest language). I could really use a pointer in the right direction to 1) tell me if what i want to do is possible on proffieboard hardware and 2) point me at a reference or resource to get me started. If it works i’d be happy to share it with the community.

Thanks!

Yes, it is possible.

The code is even prepared for something like this, basically you would just need to extend ButtonBase and implement your own Read() function.

(See other files in this directory for a few examples that inherit from this class.)

The circuit you link to is reasonable, but could be made simpler.
Either way, there will be some sort of voltage divider between 3.3 volts and GND, and you will measure the voltage in the middle point using analogRead(). (Or, actually the AnalogReader class.)

You may need to calculate currents to get the results out, but there is no constant current supplies or current measuments involved. (Although I guess technically, if you read the voltage from a resistor, you are also measuring the current.)

Finally, beware that not all pins are capable of doing analogRead. If you have a V3 board, the list of pins that can do analogRead are listed here: (in the “analog” column.)

https://fredrik.hubbe.net/lightsaber/v6/

1 Like

Based on your answer i was a bit confused, for a voltage divider i believe you mean 3 pins with the divider being the pin in the middle. That would mean 2 switches on 2 pins isn’t possible but 3 switches (aux plus the other 2) on 3 pins is… if so i think i can swing that.

It’s just two (or more) resistors in serial that linearly reduce the input voltage.
Your circuit is a little more complicated, because it has buttons and additional resistors that alter the output voltage, but in principle, it’s still a voltage divider.