So, I'm writing this program, the primary function of which is switching on one of six outputs based on the data from four I/O lines from the host.
So far, my attempts have failed utterly, either because I can't program (Entirely possible.) or due to unrelated issues. (Such as hardware problems.)
Given that I have no earthly idea what I'm doing, I figured a good place to start would be to see if I was even going in the right direction with the program.
Here's how the hardware works: There are four data lines. The first one, ELCLOCK, pulses high when a switch is requested. At that same time, the other three pins, ELD0, ELD1, and ELD2 pulse what output to turn on.
eld0 | eld1 | eld2 | Result |
---|---|---|---|
LOW | LOW | LOW | output1 |
HIGH | LOW | LOW | output2 |
LOW | HIGH | LOW | output3 |
HIGH | HIGH | LOW | output4 |
LOW | LOW | HIGH | output5 |
HIGH | LOW | HIGH | output6 |
I had an interrupt attached to the input for ELCLOCK, so when it went high, the following would happen:
// Read state of eldata pins
if (digitalRead(eld2) == HIGH)
{
switchValue = 1;
}
else
{
switchValue = 0;
}
if (digitalRead(eld1) == HIGH)
{
switchValue += 2;
}
if (digitalRead(eld0) == HIGH)
{
switchValue += 4;
}
// Switch on panel determined by above function
switch(switchValue) {
case 0:
digitalWrite(panel1, HIGH);
break;
case 1:
digitalWrite(panel5, HIGH);
break;
case 2:
digitalWrite(panel3, HIGH);
break;
case 4:
digitalWrite(panel2, HIGH);
break;
case 5:
digitalWrite(panel6, HIGH);
break;
case 6:
digitalWrite(panel4, HIGH);
break;
default:
digitalWrite(panel1, HIGH);
}
I had it printing switchValue to the serial port for debugging, and besides the fact that the interrupts would happen constantly with or without input, it was returning 7.
So, before I take this any further, is this right at all or am I completely on the wrong track with this? I've tried debugging it, but on the off chance that this is one of those occasions where I have the right idea but it's failing because of some stupid error I can't spot, I don't want keep tearing up the code. (Like when you spend a whole day debugging and rewriting a PHP file, only to find out it was failing because of some misplaced whitespace somewhere...)