Advertisement
metalx1000

Digispark Joystick Arcade Controller

Sep 3rd, 2021
6,078
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.22 KB | None | 0 0
  1. //DigiJoystick test and usage documentation
  2.  
  3. #include "DigiJoystick.h"
  4.  
  5. void setup() {
  6.   pinMode(0, OUTPUT);
  7.   pinMode(1, OUTPUT);
  8. }
  9.  
  10.  
  11. void loop() {
  12.   // If not using plentiful DigiJoystick.delay() calls, make sure to
  13.   //DigiJoystick.update(); // call this at least every 50ms
  14.   // calling more often than that is fine
  15.   // this will actually only send the data every once in a while unless the data is different
  16.  
  17.   // you can set the values from a raw byte array with:
  18.   // char myBuf[8] = {
  19.   //   x, y, xrot, yrot, zrot, slider,
  20.   //   buttonLowByte, buttonHighByte
  21.   // };
  22.   // DigiJoystick.setValues(myBuf);
  23.  
  24.   // Or we can also set values like this:
  25.   DigiJoystick.setX((byte) 1); // scroll X left to right repeatedly
  26.   DigiJoystick.setButtons((byte) 1, (byte) 1);
  27.   digitalWrite(0, 1);
  28.   digitalWrite(1, 1);
  29.   // it's best to use DigiJoystick.delay() because it knows how to talk to
  30.   // the connected computer - otherwise the USB link can crash with the
  31.   // regular arduino delay() function
  32.   DigiJoystick.delay(500); // wait 50 milliseconds
  33.   DigiJoystick.setX((byte) 0); // scroll X left to right repeatedly
  34.   DigiJoystick.setButtons((byte) 1, (byte) 0);
  35.   digitalWrite(0, 0);
  36.   digitalWrite(1, 0);
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement