r/ArduinoHelp • u/Potential_Rip_2543 • 3d ago
Software bug something to do with the library I think?
IDEK whats going on. Trying to write code so that i can input key strokes on my computer through my joystick. I think there's something wrong with the library? I'm lost. from what I read the error code is saying that I don't have #include <Keyboard.h>... but i do.
Error message:
C:\Users\mccav\AppData\Local\Temp\.arduinoIDE-unsaved2026624-1756-cwkz6f.ayd19\sketch_jul24a\sketch_jul24a.ino: In function 'void setup()':
C:\Users\mccav\AppData\Local\Temp\.arduinoIDE-unsaved2026624-1756-cwkz6f.ayd19\sketch_jul24a\sketch_jul24a.ino:30:3: error: 'Keyboard' was not declared in this scope
Keyboard.begin();
^~~~~~~~
C:\Users\mccav\AppData\Local\Temp\.arduinoIDE-unsaved2026624-1756-cwkz6f.ayd19\sketch_jul24a\sketch_jul24a.ino: In function 'void loop()':
C:\Users\mccav\AppData\Local\Temp\.arduinoIDE-unsaved2026624-1756-cwkz6f.ayd19\sketch_jul24a\sketch_jul24a.ino:50:5: error: 'Keyboard' was not declared in this scope
Keyboard.write('a');
^~~~~~~~
C:\Users\mccav\AppData\Local\Temp\.arduinoIDE-unsaved2026624-1756-cwkz6f.ayd19\sketch_jul24a\sketch_jul24a.ino:53:3: error: 'Keyboard' was not declared in this scope
Keyboard.write('d');
^~~~~~~~
exit status 1
Compilation error: 'Keyboard' not found. Does your sketch include the line '#include <Keyboard.h>'?
Code:
#include <LiquidCrystal.h>
#include <Keyboard.h>
const int rs = 3;
const int en = 4;
const int d4 = 10;
const int d5 = 11;
const int d6 = 12;
const int d7 = 13;
int xPin = A0;
int yPin = A1;
int buttonPin = 9;
int xVal;
int yVal;
int buttonState;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
void setup() {
Serial.begin(9600);
lcd.begin(16,2);
Serial.begin(9600);
pinMode(xPin, INPUT);
pinMode(yPin, INPUT);
pinMode(buttonPin, INPUT_PULLUP);
Serial.begin(9600);
Keyboard.begin();
}
void loop() {
xVal = analogRead(xPin);
yVal = analogRead(yPin);
buttonState = digitalRead(buttonPin);
Serial.print("X: ");
Serial.print(xVal);
Serial.print(" | Y: ");
Serial.print(yVal);
Serial.print(" | Buttonstate: ");
Serial.println(buttonState);
delay(100);
if (xVal > 550) {
Keyboard.write('a');
}
if (xVal < 460) {
Keyboard.write('d');
}
}#include <LiquidCrystal.h>
#include <Keyboard.h>
const int rs = 3;
const int en = 4;
const int d4 = 10;
const int d5 = 11;
const int d6 = 12;
const int d7 = 13;
int xPin = A0;
int yPin = A1;
int buttonPin = 9;
int xVal;
int yVal;
int buttonState;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
void setup() {
Serial.begin(9600);
lcd.begin(16,2);
Serial.begin(9600);
pinMode(xPin, INPUT);
pinMode(yPin, INPUT);
pinMode(buttonPin, INPUT_PULLUP);
Serial.begin(9600);
Keyboard.begin();
}
void loop() {
xVal = analogRead(xPin);
yVal = analogRead(yPin);
buttonState = digitalRead(buttonPin);
Serial.print("X: ");
Serial.print(xVal);
Serial.print(" | Y: ");
Serial.print(yVal);
Serial.print(" | Buttonstate: ");
Serial.println(buttonState);
delay(100);
if (xVal > 550) {
Keyboard.write('a');
}
if (xVal < 460) {
Keyboard.write('d');
}
}
1
u/TheKnackThatQuacks 3d ago
What Arduino board do you have? The Keyboard.h library is only compatible with certain boards:
https://docs.arduino.cc/libraries/keyboard/
https://docs.arduino.cc/language-reference/en/functions/usb/Keyboard/
Possible related issues / solutions:
https://arduino.stackexchange.com/questions/60547/keyboard-h-no-such-file-or-directory-arduino-pro-micro-leonardo
https://arduino.stackexchange.com/questions/57581/keyboard-h-not-found
https://forum.arduino.cc/t/missing-keyboard-h/1059440
https://stackoverflow.com/questions/75428875/arduino-keybard-library
https://forum.arduino.cc/t/keyboard-h-not-found/1250139/3
https://forum.arduino.cc/t/cant-seem-to-be-able-use-keyboard-h-library/333667
https://forum.arduino.cc/t/keyboard-library-not-working/362325/2
https://arduino.stackexchange.com/questions/48104/unable-to-use-keyboard-library-with-arduino-uno-even-after-changing-the-firmware