As stated, i am getting a compiler error and i have no idea whats causing the error. It looks right to me, though im not too experienced in coding in this language. The board im using is the Leonardo
#define DELAY 5 // Delay per loop in ms
enum PinAssignments
{
encoderPinA = 0,
encoderPinB = 1,
encoderPinC = 3,
encoderPinD = 2,
};
//This is up to your pin wiring
int encoderPos[] = {0,0};
static boolean rotating[] = {false,false};
boolean A_set = false;
boolean B_set = false;
boolean C_set = false;
boolean D_set = false;
void setup()
{
pinMode(4, INPUT_PULLUP);
pinMode(A0, INPUT_PULLUP);
pinMode(A1, INPUT_PULLUP);
pinMode(A2, INPUT_PULLUP);
pinMode(A3, INPUT_PULLUP);
pinMode(A4, INPUT_PULLUP);
pinMode(A5, INPUT_PULLUP);
Keyboard.begin();
pinMode(encoderPinA, INPUT_PULLUP);
pinMode(encoderPinB, INPUT_PULLUP);
pinMode(encoderPinC, INPUT_PULLUP);
pinMode(encoderPinD, INPUT_PULLUP);
attachInterrupt(0, doEncoderC, CHANGE);
attachInterrupt(1, doEncoderD, CHANGE);
attachInterrupt(2, doEncoderA, CHANGE);
attachInterrupt(3, doEncoderB, CHANGE);
Serial.begin(9600);
}
void loop() {
if(digitalRead(4)==LOW){
Keyboard.press('a');
}
if(digitalRead(4)==HIGH){
Keyboard.release('a');
}
if(digitalRead(A0)==LOW){
Keyboard.press('b');
}
if(digitalRead(A0)==HIGH){
Keyboard.release('b');
}
if(digitalRead(A1)==LOW){
Keyboard.press('c');
}
if(digitalRead(A1)==HIGH){
Keyboard.release('c');
}
if(digitalRead(A2)==LOW){
Keyboard.press('d');
}
if(digitalRead(A2)==HIGH){
Keyboard.release('d');
}
if(digitalRead(A3)==LOW){
Keyboard.press('i');
}
if(digitalRead(A3)==HIGH){
Keyboard.release('i');
}
if(digitalRead(A4)==LOW){
Keyboard.press('f');
}
if(digitalRead(A4)==HIGH){
Keyboard.release('f');
}
if(digitalRead(A5)==LOW){
Keyboard.press('g');
}
if(digitalRead(A5)==HIGH){
Keyboard.release('g');
}
//Encoder Reset
for(int i=0;i<=1;i++)
{
rotating[i] = true;
if (encoderPos[i] != 0)
{
if(i==0) Mouse.move(encoderPos[i],0,0);
if(i==1) Mouse.move(0,encoderPos[i],0);
encoderPos[i] = 0;
}
}
delay(DELAY);
}
void doEncoderA()
{
if( digitalRead(encoderPinA) != A_set )
{
A_set = !A_set;
if ( A_set && !B_set )
encoderPos[0] += 1;
rotating[0] = false;
}
}
void doEncoderB()
{
if( digitalRead(encoderPinB) != B_set ) {
B_set = !B_set;
if( B_set && !A_set )
encoderPos[0] -= 1;
rotating[0] = false;
}
}
void doEncoderC()
{
if( digitalRead(encoderPinC) != C_set )
{
C_set = !C_set;
if ( C_set && !D_set )
encoderPos[1] += 1;
rotating[1] = false;
}
}
here is my compiler error
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino\wiring.c: In function 'init':
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino\wiring.c:318:3: warning: #warning Timer 2 not finished (may not be present on this CPU) [-Wcpp]
#warning Timer 2 not finished (may not be present on this CPU)
^
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino\wiring.c:327:3: warning: #warning Timer 2 not finished (may not be present on this CPU) [-Wcpp]
#warning Timer 2 not finished (may not be present on this CPU)
^
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino\Tone.cpp:212:12: warning: #warning this may not be correct [-Wcpp]
#warning this may not be correct
^
In file included from C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino\USBAPI.h:38:0,
from C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino\USBCore.cpp:19:
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino\USBCore.cpp: In function 'bool SendConfiguration(int)':
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino\USBCore.h:285:91: warning: narrowing conversion of 'interfaces' from 'int' to 'u8 {aka unsigned char}' inside { } is ill-formed in C++11 [-Wnarrowing]
{ 9, 2, _totalLength,_interfaces, 1, 0, USB_CONFIG_BUS_POWERED, USB_CONFIG_POWER_MA(500) }
^
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino\USBCore.cpp:471:28: note: in expansion of macro 'D_CONFIG'
ConfigDescriptor config = D_CONFIG(_cmark + sizeof(ConfigDescriptor),interfaces);
^
avr-gcc: error: sketch_oct29a.cpp.o: No such file or directory
Error compiling.