I am using an Arduino Uno as a game input controller for Unity.
I have two buttons and am trying to get three states (buttonA, buttonB, both buttonA+ buttonB)
So far, both buttons work, but Unity does not recognize both buttons being pressed at the same time.
I am trying to create a string with a separator that can then be converted to an array in Unity, so Unity will recognize when both buttons are being pushed, but I don't know how to concatenate both of the Serial.print outputs into a string.
MorganS - Thank you! I didn't realize the Arduino could recognize two inputs at the same time, for some reason I thought it just checked one at a time very quickly. I was able to restructure my code to do exactly what I wanted.
Those aren't good tests.
You can read the entire PORT (all 8 pins at once) and make decisions from there, vs reading the pins multiple times.
portRead = PORTD; // capture state of D7 to D0
portRead = (portRead && 0b11000000); // mask off the lower bits that are not used
switch (portRead){
case 0b00000000:
// value 0 actions
break;
case 0b01000000:
// value 1 actions
break;
case 0b10000000;
// value 2 actions
break;
case 0b11000000:
// value 3 actions
break;
}
Because buttons are read more than once, I suppose there is a minuscule chance that a button is read in one state at one time and in another state at another time. It would be better at the beginning to read each button and save its state, or even read the entire port and save the value of these two buttons. Then there would zero chance of a value changing while the decision process is going on.