#include <Keyboard.h>
#include <Encoder.h>
#include <Joystick.h>
//button press assignment
int button0 = 0;
int button1 = 1;
int button2 = 2;
int button3 = 3;
int button4 = 4;
int button5 = 5;
int button6 = 6;
int button7 = 7;
//encoder turns assignment
int kll = 8;
int klr = 9;
int krl = 10;
int krr = 14;
int kml = 15;
int kmr = 16;
Encoder knobLeft(8, 9);
Encoder knobRight(10, 14);
Encoder knobMiddle(15, 16);
//joystick assignment
Joystick_ leftJoystick(0x01, JOYSTICK_TYPE_JOYSTICK, 2, 0, false, false, false, false, false, false, false, false, false, false, false);
Joystick_ rightJoystick(0x02, JOYSTICK_TYPE_JOYSTICK, 2, 0, false, false, false, false, false, false, false, false, false, false, false);
const bool testAutoSendMode = true;
int LJV;
int LJH = 19;
int RJV = 20;
int RJH = 21;
int iLJV = 0;
int iLJH = 0;
int iRJV = 0;
int iRJH = 0;
int nLJV;
int nLJH;
int nRJV;
int nRJH;
int mLJV = A0;
int mLJH = A1;
int mRJV = A2;
int mRJH = A3;
void setup()
{
leftJoystick.begin();
rightJoystick.begin();
Keyboard.begin();
pinMode(button0, INPUT_PULLUP);
pinMode(button1, INPUT_PULLUP);
pinMode(button2, INPUT_PULLUP);
pinMode(button3, INPUT_PULLUP);
pinMode(button4, INPUT_PULLUP);
pinMode(button5, INPUT_PULLUP);
pinMode(button6, INPUT_PULLUP);
pinMode(button7, INPUT_PULLUP);
pinMode(kll, INPUT_PULLUP);
pinMode(klr, INPUT_PULLUP);
pinMode(krl, INPUT_PULLUP);
pinMode(krr, INPUT_PULLUP);
pinMode(kml, INPUT_PULLUP);
pinMode(kmr, INPUT_PULLUP);
pinMode(mLJV, INPUT);
pinMode(mLJH, INPUT);
pinMode(mRJV, INPUT);
pinMode(mRJH, INPUT);
long positionLeft = -999;
long positionRight = -999;
long positionMiddle = -999;
}
void loop()
{
iLJV = analogRead(mLJV);
iLJH = analogRead(mLJH);
iRJV = analogRead(mRJV);
iRJH = analogRead(mRJH);
int LJV = map(mLJV, 0, 1023, -127, 127);
int LJH = map(mLJH, 0, 1023, -127, 127);
int RJV = map(mRJV, 0, 1023, -127, 127);
int RJH = map(mRJH, 0, 1023, -127, 127);
leftJoystick.setXAxis(mLJH);
leftJoystick.setYAxis(mLJV);
rightJoystick.setXAxis(mRJH);
rightJoystick.setYAxis(mRJV);
leftJoystick.sendState();
rightJoystick.sendState();
delay(50);
long nLeft, nRight, nMiddle;
int Left = knobLeft.read();
int Middle = knobMiddle.read();
int Right = knobRight.read();
nLeft = knobLeft.read();
nMiddle = knobMiddle.read();
nRight = knobRight.read();
char outputLeft = ' ';
char outputMiddle = ' ';
char outputRight = ' ';
if (nLeft != Left || nRight != Right || nMiddle != Middle)
{
if (nLeft < Left)
{
outputLeft = 'k';
Keyboard.press('k');
Keyboard.releaseAll();
}
else if (nLeft > Left)
{
outputLeft = 'r';
Keyboard.press('r');
Keyboard.releaseAll();
}
if (nRight < Right)
{
outputRight = 'z';
Keyboard.press('z');
Keyboard.releaseAll();
}
else if (nRight > Right)
{
outputRight = 'x';
Keyboard.press('x');
Keyboard.releaseAll();
}
if (nMiddle < Middle)
{
outputMiddle = 'n';
Keyboard.press('n');
Keyboard.releaseAll();
}
else if (nMiddle > Middle)
{
outputMiddle = 'm';
Keyboard.press('m');
Keyboard.releaseAll();
}
if(button0 != LOW)
{
Keyboard.press("a");
Keyboard.releaseAll();
}
if(button1 != LOW)
{
Keyboard.press("b");
Keyboard.releaseAll();
}
if(button2 != LOW)
{
Keyboard.press("c");
Keyboard.releaseAll();
}
if(button3 != LOW)
{
Keyboard.press("d");
Keyboard.releaseAll();
}
if(button4 != LOW)
{
Keyboard.press("e");
Keyboard.releaseAll();
}
if(button5 != LOW)
{
Keyboard.press("f");
Keyboard.releaseAll();
}
if(button6 != LOW)
{
Keyboard.press("g");
Keyboard.releaseAll();
}
if(button7 != LOW)
{
Keyboard.press("h");
Keyboard.releaseAll();
}
}
}
This is my code, the purpose is this: Sends different key inputs depending how the rotary encoder is turned. Send joystick inputs. Sends keypress if a button is pressed, I have compiled and check myself so logic errors. Does anyone have any logic errors they can see? Everything is sent over HID