system
April 28, 2014, 12:13pm
1
Hey there,
I'm working on a midi-decoder at the moment that will read in midi data and control 32 solenoids.
I've written the decoder using the midi library and I'm currently holding the status of the solenoids in a 32 position boolean array.
I planned to put 8 bits of data onto a databus (pins4-11) and then latch the Octal flip-flops using rising clock edge from pins 14-17.
But I'm stuck in how to cycle through the array 8 positions at a time without a nasty chain of "if" statements?
What is the most efficient way?
system
April 28, 2014, 12:19pm
2
What is the most efficient way?
Using a for loop, with an increment of 8.
In the absence of any code, that's all the help you're going to get.
void outputUpdate()
{
int i;
int counter = 0;
for(i=0; i <32; i+8)
{
digitalWrite(3, NoteStatus[i]); //bit0
digitalWrite(4, NoteStatus[i+1]); //bit1
digitalWrite(5, NoteStatus[i+2]); //bit2
digitalWrite(6, NoteStatus[i+3]); //bit3
digitalWrite(7, NoteStatus[i+4]); //bit4
digitalWrite(8, NoteStatus[i+5]); //bit5
digitalWrite(9, NoteStatus[i+6]); //bit6
digitalWrite(10, NoteStatus[i+7]); //bit7
digitalWrite(14 + counter, HIGH); //Clock signal for latch
digitalWrite(14 + counter, LOW);
counter++;
}
counter = 0;
}
Is this the most efficient way to map the outputs? There are two serial ports running on the board and I'm trying to make sure I don't loose any incoming data.
Thanks,
for(i=0; i <32; i+8)
Perhaps you should print out the value of i on each pass through loop. You'd see:
0
0
0
0
0
0
0
0
0
0
Until you got tired of watching.
Next time, you might want to see the people at http://snippets-r-us.com . They are far better at helping you with snippets than we are.