The sample sketch from here Keyboard.write() - Arduino Reference
is giving me an error.
#include <Keyboard.h>
int run;
int buttonPin;
void setup()
{
run = 0; //starts stopped
buttonPin = 7; //whatever pin your button is plugged into
pinMode(buttonPin, INPUT_PULLUP);
}
void loop()
{ // make pin 2 an input and turn on the
// pullup resistor so it goes high unless
// connected to ground:
pinMode(2, INPUT_PULLUP);
Keyboard.begin(65);
}
//code you always run here; you can leave this section blank if you want the entire program to stop and start, or add code here if you want it to always run
//check button press here and if it is pressed then toggle run variable between 0 and 255; REQUIRED!
if(digitalRead(buttonPin) == LOW) //funcitons based off of button pulling input pin LOW
{
if(run == 0)
{
run = 255;
}
else
{
run = 0;
}
}
if(run > 0)
{
//code you only run if button was pressed, stops running when button pressed again, so forth...
}
}
Error Messages: Arduino: 1.8.12 (Windows Store 1.8.33.0) (Windows 10), Board: "Arduino Leonardo"
C:\Users\samne\AppData\Local\Temp\arduino_modified_sketch_280712\sketch_apr26b.ino: In function 'void setup()':
sketch_apr26b:8:3: error: 'Keyboard' not found. Does your sketch include the line '#include <Keyboard.h>'?