Hi!
I'm trying to make an arcade controller for iPad (iCade controller) with my arduino Leonardo, but I some probelms.
when I push a button, the arduino will send a character, and when I release the button, the arduino will send a different character.
my code looks like this:
void setup() {
pinMode(0, INPUT_PULLUP);
pinMode(1, INPUT_PULLUP);
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
pinMode(4, INPUT_PULLUP);
pinMode(5, INPUT_PULLUP);
pinMode(6, INPUT_PULLUP);
pinMode(7, INPUT_PULLUP);
pinMode(8, INPUT_PULLUP);
pinMode(9, INPUT_PULLUP);
pinMode(10, INPUT_PULLUP);
pinMode(11, INPUT_PULLUP);
Keyboard.begin();
}
void loop() {
if(digitalRead(0) == LOW) //UP
{ Keyboard.press('w'); }
else(Keyboard.release('w'));
if(digitalRead(0) != LOW)
{ Keyboard.press('e'); }
else(Keyboard.release('e'));
if(digitalRead(1) == LOW) //DOWN
{ Keyboard.press('x'); }
else(Keyboard.release('x'));
if(digitalRead(1) != LOW)
{ Keyboard.press('z'); }
else(Keyboard.release('z'));
if(digitalRead(2) == LOW) //LEFT
{ Keyboard.press('a'); }
else(Keyboard.release('a'));
if(digitalRead(2) != LOW)
{ Keyboard.press('q'); }
else(Keyboard.release('q'));
if(digitalRead(3) == LOW) //RIGHT
{ Keyboard.press('d'); }
else(Keyboard.release('d'));
if(digitalRead(3) != LOW)
{ Keyboard.press('c'); }
else(Keyboard.release('c'));
if(digitalRead(4) == LOW) //A
{ Keyboard.press('y'); }
else(Keyboard.release('y'));
if(digitalRead(4) != LOW)
{ Keyboard.press('t'); }
else(Keyboard.release('t'));
if(digitalRead(5) == LOW) //B
{ Keyboard.press('h'); }
else(Keyboard.release('h'));
if(digitalRead(5) != LOW)
{ Keyboard.press('r'); }
else(Keyboard.release('r'));
if(digitalRead(6) == LOW) //C
{ Keyboard.press('u'); }
else(Keyboard.release('u'));
if(digitalRead(6) != LOW)
{ Keyboard.press('f'); }
else(Keyboard.release('f'));
if(digitalRead(7) == LOW) //D
{ Keyboard.press('j'); }
else(Keyboard.release('j'));
if(digitalRead(7) != LOW)
{ Keyboard.press('n'); }
else(Keyboard.release('n'));
if(digitalRead(8) == LOW) //E
{ Keyboard.press('i'); }
else(Keyboard.release('i'));
if(digitalRead(8) != LOW)
{ Keyboard.press('m'); }
else(Keyboard.release('m'));
if(digitalRead(9) == LOW) //F
{ Keyboard.press('k'); }
else(Keyboard.release('k'));
if(digitalRead(9) != LOW)
{ Keyboard.press('p'); }
else(Keyboard.release('p'));
if(digitalRead(10) == LOW) //G
{ Keyboard.press('o'); }
else(Keyboard.release('o'));
if(digitalRead(10) != LOW)
{ Keyboard.press('g'); }
else(Keyboard.release('g'));
if(digitalRead(11) == LOW) //H
{ Keyboard.press('l'); }
else(Keyboard.release('l'));
if(digitalRead(11) != LOW)
{ Keyboard.press('y'); }
else(Keyboard.release('y'));
}
This code worked flawlessly with only six buttons in the code (including //B), but now, with 12 buttons, the arduino don't respont on button presses and sometimes output wrong caracters.
Whats wrong? can it be RAM limitations?