Error Compiling Help

Semi nube to arduino, total nube to programming. I enetered inn a sketch that I screen shotted.... To The T btw. But getting this error messege.."C:\Users\G\Documents\Arduino\Sequential_Shifter\Sequential_Shifter.ino: In function 'void setup()':
C:\Users\G\Documents\Arduino\Sequential_Shifter\Sequential_Shifter.ino:6:10: error: expected unqualified-id before '.' token
Joystick.begin();
^
C:\Users\G\Documents\Arduino\Sequential_Shifter\Sequential_Shifter.ino: In function 'void loop()':
C:\Users\G\Documents\Arduino\Sequential_Shifter\Sequential_Shifter.ino:14:6: error: expected '(' before 'int'
for int index = 0; index < 2; index++)
^~~
C:\Users\G\Documents\Arduino\Sequential_Shifter\Sequential_Shifter.ino:18:14: error: expected unqualified-id before '.' token
{Joystick.setButton(index, currentButtonState);
^

exit status 1
here is the sketch.. can someone please help

#include <Joystick.h>
void setup() {
  pinMode(2, INPUT_PULLUP);
  pinMode(3, INPUT_PULLUP);

 Joystick.begin();
}
const int pinToButtonMap = 2;

int lastButtonState[4] = {0,0};

void loop() {

for  int index = 0; index < 2; index++)
  { 
    int currentButtonState = !digitalRead(index + pinToButtonMap);
    if (currentButtonState != lastButtonState[index])
    {Joystick.setButton(index, currentButtonState);
      lastButtonState[index] = currentButtonState;}
    }
delay(50);
}

You have to declare Joystick first. Didn't you see the library examples?

1 Like

Look at the syntax of a 'for loop' online - you should see whats missing.

1 Like

I worked it out thanks

Do you mean declare its pin? like if Im using the ground pin to signal the microswitches on pins 2 and 3? would that be Joystick.begin(1); or (GND); ?

@rodeo515000
If your code is different from examples given, you'll need to explain why; at the newbie level, I think you'll have a hard time doing that, so perhaps go look at the examples again.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.