I'm working on a MIDI instrument which uses 6 buttons hooked up to digital inputs to determine what the pitch will be. I've been hacking together the code from looking at other people's work and now have the following parts (not the WHOLE sketch though) :
// Define Variables
int keyPins[] = {0, 1, 2, 3, 4, 5}; // What digital inputs the 6 keys are attached to
int keyStates[6]; // Array to store the state of the keys
int keyStatesOld[6]; // Array to store previous state of the keys (used for debouncing/determining any change)
// Read the status of the keys and store them in an array
void scanKeys()
{
pinMode(keyPins[i], INPUT); // Set the digital inputs of the keys to input mode
keyStatesOld[i] = keyStates[i];
keyStates[i] = digitalRead(keyPins[i]);
}
So lets imagine I have my six keys pressed like this : 0(OFF), 1(ON), 2(OFF), 3(ON), 4(OFF), 5(OFF)
Does that mean keyStates array values will be {0, 1, 0, 1, 0, 0}? As in, does storing digitalRead information as an integer automatically change it to binary from HIGH and LOW?
I'm trying to work out what data the digitalRead function will put into the array so I can then write a stack of CASES that will decode the key fingering into a note value to pass to MIDI.
holmes4:
you have 7 values for a 6 element array this will over write somthing else and mark a real mess to the program.
Mark
I've amended original post - typo with an extra 0 on my behalf.
raschemmel:
Big Endian or Little Endian ? (MSB left justified or MSB right justified )
Big Endian, I think. I'm just trying to find out how the data will be stored - how does a HIGH or LOW response from digitalRead get stored in an int array?
In taking a break from mashing the keyboard, I found that I was approaching the problem from a completely wrong direction. I'd actually designed a solution into the fingering scheme I'd come up with for the instruments.
Standard Operating Procedure (SOP) on the forum is that when the OP finds the solution, regardless of how or by whom, even if he solves his own problem, the OP then posts his solution to help others who may someday be faced with that problem. When he posts the solution he first has to terminate his post seeking help in a manner that doesn't leave everyone thinking he was abducted by alien in between posts. You have pretty much already done that (minus the comment "I will post the solution with a different post title). So then he creates a totally new post using most or all of his previous post title with one change: At the beginning of the title is the word "SOLVED: " (in CAPS) followed by his original post title (so everyone will know it is the same poster) "I've got button status stored in an array... but how is it stored?" the end result looks like this:
SOLVED: : I've got button status stored in an array... but how is it stored?
The people who were following your original post will recognize the title and think to themselves "Oh, he got it working ! I wonder how he did it ? I'm going to read that..."
That's how we roll here on the forum. Of course there are always selfish people who couldn't give a rat's ass about anyone and never bother to post their solution, but we don't think you are one of those.....
Does that mean keyStates array values will be {0, 1, 0, 1, 0, 0, 0}?
Big Endian or Little Endian ? (MSB left justified or MSB right justified )
Endianness makes no difference, unless you are trying to access the individual bytes of the int. The values are indeed stored the way the OP supposed, and it doesn't matter whether they are byte, int, or long, when looked at as values stored in a data type.
Does that mean keyStates array values will be {0, 1, 0, 1, 0, 0}? As in, does storing digitalRead information as an integer automatically change it to binary from HIGH and LOW?
This is part of the question the OP asked.
As you have pointed out , the OP has correctly supposed the 0\1 states, in the correct order, but appears to be asking if the resulting array automatically becomes BINARY. (which is a data type or a name for a value that only has two states HIGH/LOW).
does storing digitalRead information as an integer automatically change it to binary from HIGH and LOW?
Big Endian/Little Endian are only relevant if you are referring to actual binary data either serial or parallel and want to read it but don't know the format (either due to lack of documentation for the device or for some other reason). That does not apply here so yes your right, in this case , it makes no difference. Here is another part:
how does a HIGH or LOW response from digitalRead get stored in an int array?
I'm trying to work out what data the digitalRead function will put into the array so I can then write a stack of CASES that will decode the key fingering into a note value to pass to MIDI.
I think the OP has already figured out that his CASE stack will work with the state order he supposed in his original post. Do you have anything else to add for the OP or are you just responding to correct my statement ? (which doesn't seem to matter now anyway because the OP has already stated he found a solution.)
raschemmel:
I think the OP has already figured out that his CASE stack will work with the state order he supposed in his original post. Do you have anything else to add for the OP or are you just responding to correct my statement ? (which doesn't seem to matter now anyway because the OP has already stated he found a solution.)
About all I would add to the OP's question would be to advise him to not use int, and rather, use bool or byte. I haven't looked at the generated code for a bool, but I figure a good compiler, optimizing for size, would use bits for bool storage, but even if a bool is stored as a byte, it would still make more sense than an int.
As for the correction, I posted it for the OP, in order to point out that endianness really didn't matter for his purposes.