/* Basic USB Joystick Example
Teensy becomes a USB joystick
You must select Joystick from the "Tools > USB Type" menu
Pushbuttons should be connected to digital pins 0 and 1.
Wire each button between the digital pin and ground.
Potentiometers should be connected to analog inputs 0 to 1.
This example code is in the public domain.
*/
void setup() {
pinMode(0, INPUT_PULLUP); //A
pinMode(1, INPUT_PULLUP); //B
pinMode(2, INPUT_PULLUP); //X
pinMode(3, INPUT_PULLUP); //Y
pinMode(4, INPUT_PULLUP); //DUP
pinMode(5, INPUT_PULLUP); //DDOWN
pinMode(6, INPUT_PULLUP); //DLEFT
pinMode(7, INPUT_PULLUP); //DRIGHT
pinMode(8, INPUT_PULLUP); //START
pinMode(9, INPUT_PULLUP); //SELECT
pinMode(10, INPUT_PULLUP); //L1
pinMode(11, INPUT_PULLUP); //L2
pinMode(12, INPUT_PULLUP); //R1
pinMode(13, INPUT_PULLUP); //R2
pinMode(14,INPUT_PULLUP); //x axis 1
pinMode(15,INPUT_PULLUP); //y axis 1
pinMode(16,INPUT_PULLUP); // x axis 2
pinMode(17,INPUT_PULLUP);// y axis 2
}
void loop() {
// read analog inputs and set X-Y position
Joystick.X(analogRead(0));
Joystick.Y(analogRead(1));
Joystick.sliderLeft(analogRead(2));
Joystick.sliderRight(analogRead(3));
// read the digital inputs and set the buttons
Joystick.button(1, digitalRead(0));
Joystick.button(2, digitalRead(1));
Joystick.button(3, digitalRead(2));
Joystick.button(4, digitalRead(3));
Joystick.button(5, digitalRead(4));
Joystick.button(6, digitalRead(5));
Joystick.button(7, digitalRead(6));
Joystick.button(8, digitalRead(7));
Joystick.button(9, digitalRead(8));
Joystick.button(10, digitalRead(9));
Joystick.button(11, digitalRead(10));
Joystick.button(12, digitalRead(11));
Joystick.button(13, digitalRead(12));
Joystick.button(14, digitalRead(13));
// a brief delay, so this runs 20 times per second
delay(5);
}