Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Simple gamepad example that demonstraits how to read five Arduino
- // digital pins and map them to the Arduino Joystick library.
- //
- // The digital pins 2 - 6 are grounded when they are pressed.
- // Pin 2 = UP
- // Pin 3 = RIGHT
- // Pin 4 = DOWN
- // Pin 5 = LEFT
- // Pin 6 = FIRE
- //
- // NOTE: This sketch file is for use with Arduino Leonardo and
- // Arduino Micro only.
- //
- // by Matthew Heironimus
- // 2016-11-24
- //--------------------------------------------------------------------
- #include <Joystick_ESP32S2.h>
- const float joystickCenter = 2047.5;
- Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID,JOYSTICK_TYPE_GAMEPAD,
- 1, 0, // Button Count, Hat Switch Count
- true, true, false, // X and Y, but no Z Axis
- false, false, false, // No Rx, Ry, or Rz
- false, false, // No rudder or throttle
- false, false, false); // No accelerator, brake, or steering
- float analogReadingToAxis(int AnalogValue)
- {
- return (4095 - (4095 / 2)) / 2047.5;
- }
- void setup() {
- // Initialize Joystick Library
- Joystick.begin();
- Joystick.setXAxisRange(-1, 1);
- Joystick.setYAxisRange(-1, 1);
- }
- void loop() {
- Joystick.setXAxis( analogReadingToAxis( analogRead(2) ) );
- Joystick.setYAxis( analogReadingToAxis( analogRead(3) ) );
- delay(10);
- }
Advertisement
Add Comment
Please, Sign In to add comment