So I'm essentially trying to make a SNES USB gamepad using a Teensy 2.0++ via Teensyduino. I found some existing code for this project, but it doesn't work properly, so I'm making a new program based off elements from the old one. Basically my issue is this:
I'm trying to have the programm send the key "A" when I press the A button. I've got the pin set correctly, and I've created a variable called "valA" to get the state of the A button, but nothing happens when I press it.
Here's my code:
const int pinBtnUp = 0;
const int pinBtnRight = 1;
const int pinBtnDown = 2;
const int pinBtnLeft = 3;
const int pinBtnSelect = 4;
const int pinBtnStart = 5;
const int pinBtnB = 6;
const int pinBtnA = 7;
const int pinBtnY = 8;
const int pinBtnX = 9;
const int pinBtnTrigLeft = 10;
const int pinBtnTrigRight = 11;
int valA = digitalRead(pinBtnA);
int valB = digitalRead(pinBtnB);
int valX = digitalRead(pinBtnX);
int valY = digitalRead(pinBtnY);
int valU = digitalRead(pinBtnUp);
int valD = digitalRead(pinBtnDown);
int valL = digitalRead(pinBtnLeft);
int valR = digitalRead(pinBtnRight);
int valST = digitalRead(pinBtnStart);
int valSL = digitalRead(pinBtnSelect);
int valRT = digitalRead(pinBtnTrigRight);
int valLT = digitalRead(pinBtnTrigLeft);
byte buttons[] = {pinBtnUp, pinBtnRight, pinBtnDown, pinBtnLeft, pinBtnSelect, pinBtnStart,
pinBtnB, pinBtnA, pinBtnY, pinBtnX, pinBtnTrigLeft, pinBtnTrigRight};
#define NUMBUTTONS sizeof(buttons)
void setup() {
for (byte i=0; i< NUMBUTTONS; i++) {
pinMode(buttons[i], INPUT_PULLUP);
}
Serial.begin(38400);
}
void loop() {
if(valA == HIGH) {
Keyboard.press(KEY_A);
Serial.print("A pressed");
}
}
Edit: Fixed it. Kind of obvious in retrospect. Sorry, still kinda new to Arduino programming haha