In this post, I will be talking about my switches which are done with an interrupt on Arduino Mega's pin#2, and just of keeping my head on straight the interrupt service routines name is isr2. First, let me digress. The Fuel Load Indicator has two (2) switches and each has two (2) positions for a total of four (4) switch selections. So how do I generate the interrupt?
One way is to connect the four wires (a, b, c, d) to the Arduino and then use a quad 2-input or-gate, SN74LS32. As shown in the table below. And then you have to guess which switch was used.
The second way is to use a priority encoder SN74LS148. The encoder has 7 inputs and 3-Bit BCD code for the output. Below is a table of its states, and I will not be using the zero state, which is the bottom row in the table.
Basically, the priority encoder just gives us the BCD number of the switch, plus a positive or negative signal EO/GS when a switch is thrown. which is connected to the interrupt pin, and in this case is pin 2 hence the name isr2. Depending on what my oscilloscope says I might need to use a Schmitt Trigger on each of the inputs, and most likely another Schmitt Trigger on ether the EO or GS line.
// pins 30, 31, 32 are A, B, C respectively
volatile retval; // This value is used in another function;
A = digitalRead (30);
B = digitalRead (31);
C = digitalRead (32);
A << 1;
A =+ B;
A << 1;
retval = A;