Hey, I'm pretty new to Arduino and I am currently making a macro pad with 5 switches and a rotary encoder. I've downloaded and installed the SparkFun Pro Micro and the first time I've tried to verify and upload it says this:
< #include <HID-Project.h>
#include <HID-Settings.h>
#include <Encoder.h>
#include <Bounce2.h>
#include <Keyboard.h>
//Set up the button grid
const int numButtons = 5;
const int buttonPins[numButtons] = {9,8,7,6,5}; //defining the pins in an order from right to left
int state = 0; //Set the current state
//Set up all the buttons as bounce objects
Bounce buttons[x] = {Bounce(buttonPins[0],10),Bounce(buttonPins[1],10),Bounce(buttonPins[2],10),Bounce(buttonPins[3],10),Bounce(buttonPins[4],10)};
//Set up the encoder
const int encoderButtonPin = 10;
Encoder volumeKnob(14,15); //Set up the encoder as an Encoder object
Bounce encoderButton = Bounce(encoderButtonPin,10); //Set up to the encoder button as a Bounce object
int timeLimit = 500; //Cut off time for play/pause or skip
void setup() {
Serial.begin(9600);
Keyboard.begin(); //Start the Keyboard object
for(int i = 0; i < numButtons; i++){
pinMode(buttonPins[i], INPUT_PULLUP);
}
pinMode(encoderButtonPin, INPUT_PULLUP);
long positionLeft = -999;
}
void loop() {
//check all buttons
for(int j = 0; j < numButtons; j++){
if(buttons[j].update()){
if(buttons[j].fallingEdge()){
//Serial.write("Button");
//use the current state and the button number to find the command needed and send it.
switch (state) {
case 0: //Layout 1
switch (j) {
case 0: //F6
Keyboard.press(KEY_F1);
delay(100);
Keyboard.releaseAll();
break;
case 1: //
Keyboard.press(KEY_F2);
delay(100);
Keyboard.releaseAll();
break;
case 2: //
Keyboard.press(KEY_F3);
delay(100);
Keyboard.releaseAll();
break;
case 3: //
Keyboard.press(KEY_F4);
delay(100);
Keyboard.releaseAll();
break;
case 4: //
Keyboard.press(KEY_F5);
delay(100);
Keyboard.releaseAll();
break;
}
}
//encoder play pause
if(encoderButton.update()) {
if(encoderButton.fallingEdge()) {
int fall = millis();
while(!encoderButton.update()){}
if(encoderButton.risingEdge()){
int rise = millis();
Serial.println(rise - fall);
if(rise - fall > timeLimit){
Keyboard.press(MEDIA_NEXT);
} else {
Keyboard.press(MEDIA_PLAY_PAUSE);
}
}
Keyboard.releaseAll();
}
}
long positionLeft = -9;
long positionRight = -9;
//encoder volume changing
long newLeft;
newLeft = volumeKnob.read();
if(newLeft != positionLeft){
if((newLeft - positionLeft) > 0) {
//volumeup
Serial.println("volume up");
Keyboard.press(MEDIA_VOL_UP);
} else {
//volumedown
Serial.println("volume down");
Keyboard.press(MEDIA_VOL_DOWN);
}
Keyboard.releaseAll();
delay(200);
positionLeft = newLeft;
}
}
}
}
} >