Hello all, I recently bought my first Arduino pro micro to make a make a macro pad for fusion360 shortcuts. But before that I tried to use the keyboard library and HID project library with a rotary encoder. In that code I tried to shift applications with moving rotary encoder right and left, but i seem to have gotten an error. How to correct this
#include "Keyboard.h"
#include "HID-Project.h"
// Rotary Encoder Inputs
#define inputCLK 1
#define inputDT 2
#define inputSW 3
int currentStateCLK;
int previousStateCLK;
int mode = 1;
int maxMode = 4;
void changeMode() {
mode = (mode % maxMode) + 1;
}
void setup() {
// Set encoder pins as inputs
pinMode (inputCLK,INPUT);
pinMode (inputDT,INPUT);
pinMode(inputSW, INPUT_PULLUP);
// Setup Serial Monitor
Serial.begin (9600);
Consumer.begin();
Keyboard.begin();
// Read the initial state of inputCLK
// Assign to previousStateCLK variable
previousStateCLK = digitalRead(inputCLK);
}
void loop() {
// Read the current state of inputCLK
currentStateCLK = digitalRead(inputCLK);
// If the previous and the current state of the inputCLK are different then a pulse has occured
if (currentStateCLK != previousStateCLK){
// If the inputDT state is different than the inputCLK state then
// the encoder is rotating counterclockwise
if (digitalRead(inputDT) != currentStateCLK) {
rotateRight();
}
else {
rotateLeft();
}
}
// Update previousStateCLK with the current state
previousStateCLK = currentStateCLK;
if(!digitalRead(inputSW)) {
changeMode();
delay(300);
}
}
void rotateLeft() {
switch(mode) {
case 1:
// Increase the volume.
Consumer.write(MEDIA_VOLUME_UP);
delay(500);
break;
case 2:
//Cltr + TAB
Keyboard.press(KEY_LEFT_CTRL);
Keyboard.press(KEY_TAB);
Keyboard.releaseAll();
delay(500);
break;
}
}
void rotateRight() {
switch(mode) {
case 1:
// Decrease the volume.
Consumer.write(MEDIA_VOLUME_DOWN);
delay(500);
break;
case 2:
//Cltr + SHIFT + TAB
Keyboard.press(KEY_LEFT_CTRL);
Keyboard.press(KEY_LEFT_SHIFT);
Keyboard.press(KEY_TAB);
Keyboard.releaseAll();
delay(500);
break;
}
}
After trying to compile the above code , I get the following error:-
In file included from C:\Users\Lenovo\Documents\Arduino\Rotary_Encoder_Multiplex\Rotary_Encoder_Multiplex.ino:1:0:
C:\Users\Lenovo\Documents\Arduino\libraries\Keyboard\src/Keyboard.h:54:27: error: expected identifier before numeric constant
#define KEY_RETURN 0xB0
^
e:\arduino ide\arduino-1.8.19-windows\arduino-1.8.19\libraries\hid_project-2.8.4\src\keyboardlayouts\improvedkeylayouts.h:103:5: note: in expansion of macro 'KEY_RETURN'
KEY_RETURN = 40, // Alias
^~~~~~~~~~
C:\Users\Lenovo\Documents\Arduino\libraries\Keyboard\src/Keyboard.h:54:27: error: expected '}' before numeric constant
#define KEY_RETURN 0xB0
^
e:\arduino ide\arduino-1.8.19-windows\arduino-1.8.19\libraries\hid_project-2.8.4\src\keyboardlayouts\improvedkeylayouts.h:103:5: note: in expansion of macro 'KEY_RETURN'
KEY_RETURN = 40, // Alias
^~~~~~~~~~
C:\Users\Lenovo\Documents\Arduino\libraries\Keyboard\src/Keyboard.h:54:27: error: expected unqualified-id before numeric constant
#define KEY_RETURN 0xB0
^
e:\arduino ide\arduino-1.8.19-windows\arduino-1.8.19\libraries\hid_project-2.8.4\src\keyboardlayouts\improvedkeylayouts.h:103:5: note: in expansion of macro 'KEY_RETURN'
KEY_RETURN = 40, // Alias
^~~~~~~~~~
In file included from e:\arduino ide\arduino-1.8.19-windows\arduino-1.8.19\libraries\hid_project-2.8.4\src\hid-apis\KeyboardAPI.h:29:0,
Multiple libraries were found for "Keyboard.h"
from e:\arduino ide\arduino-1.8.19-windows\arduino-1.8.19\libraries\hid_project-2.8.4\src\hid-apis\defaultkeyboardapi.h:27,
Used: C:\Users\Lenovo\Documents\Arduino\libraries\Keyboard
Not used: E:\Arduino IDE\arduino-1.8.19-windows\arduino-1.8.19\libraries\Keyboard
from E:\Arduino IDE\arduino-1.8.19-windows\arduino-1.8.19\libraries\HID_Project-2.8.4\src/SingleReport/BootKeyboard.h:30,
from E:\Arduino IDE\arduino-1.8.19-windows\arduino-1.8.19\libraries\HID_Project-2.8.4\src/HID-Project.h:50,
from C:\Users\Lenovo\Documents\Arduino\Rotary_Encoder_Multiplex\Rotary_Encoder_Multiplex.ino:2:
e:\arduino ide\arduino-1.8.19-windows\arduino-1.8.19\libraries\hid_project-2.8.4\src\keyboardlayouts\improvedkeylayouts.h:521:1: error: expected declaration before '}' token
};
^
exit status 1
How can I correct this??