Here's the Pro-Micro sketch I'm working through.
Having changed the 'slaveSelectPin', and deleted '#include <Joystick.h>'
there's only a 'setButton' that comes back as an error.
Code:
/*
* sketch heavily based on code provided at:
* April 2015 © blog@rr-m.org
*/
/*
Also see comments from Ignacio Hernandez-Ros & mispeaced under https://www.youtube.com/watch?v=CJjLUAgAFnQ
* On Arduino Pro Micro side it must be connected as follows:
*
* Green -> not used (or can be connected to arduino MOSI pin 16)
* Blue - GND -> arduino uno GND pin
* White - MISO -> arduino uno pin 14
* Orange – SS -> arduino uno pin 7
* Red – SCK -> arduino uno pin 15
* Black +VCC -> arduino +5V pin (or RAW if USB current is +5V already)
*
* Byte 1
* 7 - 1
* 6 - 0
* 5 - 0
* 4 - 0
* 3 - 0
* 2 - 1
* 1 - 0
* 0 - Button 6
*
* Byte 2
* 7 - Button 2
* 6 - Button 5
* 5 - Button 9
* 4 - 1 = Hat-Push?
* 3 - Button 7
* 2 - Button 13
* 1 - Button 8
* 0 - 1 = Hat-Push?
*
* Byte 3
* 7 - Button 3
* 6 - Button 10
* 5 - Hat-Left
* 4 - Hat-Up
* 3 - Hat-Right
* 2 - Hat-Down
* 1 - Button 4
* 0 - Button 1
*/
#include <SPI.h>
const int slaveSelectPin = 10;
byte pos[] = {0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01};
byte currBytes[] = {0x00, 0x00, 0x00, 0x00};
byte prevBytes[] = {0x00, 0x00, 0x00};
bool btnState, joyBtnState, prevJoyBtnState;
int bit2btn[] = {-1,-1,-1,-1,-1,-1,-1,8, -1,2,1,-1,5,7,6,5, 4,0,11,9,12,10,3,-1}; //numbers the buttons from top left to bottom right (main is D,U,press)
void setup() {
//input from wheel
Serial.begin(9600);
SPI.beginTransaction(SPISettings(1000, MSBFIRST, SPI_MODE0));
SPI.begin();
pinMode(slaveSelectPin, OUTPUT);
//output to joystick
Joystick.begin();
}
void loop() {
// tell the wheel, that we are ready to read the data now
digitalWrite(slaveSelectPin, LOW);
//read the next 4 bytes (get 2's compliment)
for(int i=0; i<4; i++)
currBytes[i] = ~SPI.transfer(0x00);
//deal with the buttons first
for(int i=0; i<3; i++) //process the three bytes
for(int b=0; b<8; b++) //one bit at a time
if((btnState=currBytes[i] & pos[b])!=(prevBytes[i] & pos[b]))
Joystick.setButton(bit2btn[(i*8)+b], btnState); //if the bit has changed send the update
joyBtnState = (currBytes[3] & pos[0]) && !(currBytes[2] & 0x3c);
if(joyBtnState != prevJoyBtnState)
Joystick.setButton(13, joyBtnState);
for(int i=0;i<3;i++)
prevBytes[i] = currBytes[i]; //finally update the just read input to the the previous input for the next cycle
prevJoyBtnState = joyBtnState;
// release the wheel
digitalWrite(slaveSelectPin, HIGH);
}
This is the error returned:
Code:
sparco: In function 'void loop()':
sparco:81: error: 'class usb_joystick_class' has no member named 'setButton'
Joystick.setButton(bit2btn[(i*8)+b], btnState); //if the bit has changed send the update
^
sparco:86: error: 'class usb_joystick_class' has no member named 'setButton'
Joystick.setButton(13, joyBtnState);
^
'class usb_joystick_class' has no member named 'setButton'