Basically im quite new to ardunio and want to make a button pad were i can press buttons and they perform macro like functions in game for example. I press button 1 and it inputs Ctrl Shift A which is bound ingame to something. have made this script but it seems to just input KL= constantly into the computer without any buttons being pressed im not sure if I have coded anything wrong it compiles fine but im unsure. I have tried to use prints to see if its using any of the statements but nothing shows up ?
Thank you
#include <Keyboard.h>
char ctrlKey = "KEY_LEFT_CTRL";
char shiftKey = "KEY_RIGHT_SHIFT";
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
setupPins();
}
void setupPins(void){
for (int i = 2; i <= 12; i++){
pinMode(i, INPUT);
digitalWrite(i, HIGH);
}
pinMode(A0, INPUT);
digitalWrite(A0, HIGH);
pinMode(A1, INPUT);
digitalWrite(A1, HIGH);
pinMode(A2, INPUT);
digitalWrite(A2, HIGH);
pinMode(A3, INPUT);
digitalWrite(A3, HIGH);
}
void loop() {
// put your main code here, to run repeatedly:
if (digitalRead(2) == LOW) {
Serial.println(digitalRead(2));
Keyboard.press(ctrlKey);
Keyboard.press(shiftKey);
Keyboard.press('a');
delay(100);
Keyboard.releaseAll();
};
if (digitalRead(3) == LOW) {
Serial.println(digitalRead(3));
Keyboard.press(ctrlKey);
Keyboard.press(shiftKey);
Keyboard.press('b');
delay(100);
Keyboard.releaseAll();
};
if (digitalRead(4) == LOW) {
Serial.println(digitalRead(4));
Keyboard.press(ctrlKey);
Keyboard.press(shiftKey);
Keyboard.press('c');
delay(100);
Keyboard.releaseAll();
};
if (digitalRead(5) == LOW) {
Serial.println(digitalRead(5));
Keyboard.press(ctrlKey);
Keyboard.press(shiftKey);
Keyboard.press('d');
delay(100);
Keyboard.releaseAll();
};
if (digitalRead(6) == LOW) {
Serial.println(digitalRead(6));
Keyboard.press(ctrlKey);
Keyboard.press(shiftKey);
Keyboard.press('e');
delay(100);
Keyboard.releaseAll();
};
if (digitalRead(7) == LOW) {
Serial.println(digitalRead(7));
Keyboard.press(ctrlKey);
Keyboard.press(shiftKey);
Keyboard.press('f');
delay(100);
Keyboard.releaseAll();
};
if (digitalRead(8) == LOW) {
Serial.println(digitalRead(8));
Keyboard.press(ctrlKey);
Keyboard.press(shiftKey);
Keyboard.press('g');
delay(100);
Keyboard.releaseAll();
};
if (digitalRead(9) == LOW) {
Serial.println(digitalRead(9));
Keyboard.press(ctrlKey);
Keyboard.press(shiftKey);
Keyboard.press('h');
delay(100);
Keyboard.releaseAll();
};
if (digitalRead(10) == LOW) {
Serial.println(digitalRead(10));
Keyboard.press(ctrlKey);
Keyboard.press(shiftKey);
Keyboard.press('i');
delay(100);
Keyboard.releaseAll();
};
if (digitalRead(11) == LOW) {
Serial.println(digitalRead(11));
Keyboard.press(ctrlKey);
Keyboard.press(shiftKey);
Keyboard.press('j');
delay(100);
Keyboard.releaseAll();
};
if (digitalRead(12) == LOW) {
Serial.println(digitalRead(12));
Keyboard.press(ctrlKey);
Keyboard.press(shiftKey);
Keyboard.press('k');
delay(100);
Keyboard.releaseAll();
};
if (digitalRead(13) == LOW) {
Serial.println(digitalRead(13));
Keyboard.press(ctrlKey);
Keyboard.press(shiftKey);
Keyboard.press('l');
delay(100);
Keyboard.releaseAll();
};
if (digitalRead(A0) == LOW) {
Serial.println(digitalRead(A0));
Keyboard.press(ctrlKey);
Keyboard.press(shiftKey);
Keyboard.press('m');
delay(100);
Keyboard.releaseAll();
};
if (digitalRead(A1) == LOW) {
Serial.println(digitalRead(A1));
Keyboard.press(ctrlKey);
Keyboard.press(shiftKey);
Keyboard.press('n');
delay(100);
Keyboard.releaseAll();
};
if (digitalRead(A2) == LOW) {
Serial.println(digitalRead(A2));
Keyboard.press(ctrlKey);
Keyboard.press(shiftKey);
Keyboard.press('o');
delay(100);
Keyboard.releaseAll();
};
if (digitalRead(A3) == LOW) {
Serial.println(digitalRead(A3));
Keyboard.press(ctrlKey);
Keyboard.press(shiftKey);
Keyboard.press('p');
delay(100);
Keyboard.releaseAll();
};
}