Advertisement
perfectly_Gray

8 speed gearshift teensy4

Oct 28th, 2020
3,995
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. USB type set to KB-MO-JOY
  3. I set the clock speed to 150 MHz bcouse who the hell needs 600 MHz for a joystick
  4. */
  5. //Pins
  6. // 2: X left
  7. // 3: X right
  8. // 4: X right extreme
  9. // 5: X up
  10. // 6: Y down
  11.  
  12. const int ledPin = 13;
  13.  
  14. void setup() {
  15. // make LED on the teensy shine
  16.   pinMode(ledPin, OUTPUT);
  17.   digitalWrite(ledPin, HIGH);
  18.  // pinMode duhh
  19.   pinMode(2, INPUT_PULLUP);
  20.   pinMode(3, INPUT_PULLUP);
  21.   pinMode(4, INPUT_PULLUP);
  22.   pinMode(5, INPUT_PULLUP);
  23.   pinMode(6, INPUT_PULLUP);
  24. // zero out the unused axis
  25.   Joystick.X(0);
  26.   Joystick.Y(0);
  27.   Joystick.Z(0);
  28.   Joystick.Zrotate(0);
  29.   Joystick.sliderLeft(0);
  30.   Joystick.sliderRight(0);
  31.   Joystick.hat(-1);
  32. }
  33.  
  34. void loop() {
  35.   // read the digital inputs and set the buttons
  36.   // "!" inverts "&&" logical_and
  37.   Joystick.button(1, !digitalRead(2)&& !digitalRead(5));
  38.   Joystick.button(2, !digitalRead(2)&& !digitalRead(6));
  39.   Joystick.button(3,  digitalRead(2)&& !digitalRead(5)&& digitalRead(3));
  40.   Joystick.button(4,  digitalRead(2)&& !digitalRead(6)&& digitalRead(3));
  41.   Joystick.button(5, !digitalRead(3)&& !digitalRead(5)&& digitalRead(4));
  42.   Joystick.button(6, !digitalRead(3)&& !digitalRead(6)&& digitalRead(4));
  43.   Joystick.button(7, !digitalRead(4)&& !digitalRead(5));
  44.   Joystick.button(8, !digitalRead(4)&& !digitalRead(6));
  45. //  Joystick.button(9, digitalRead(5)&& digitalRead(6));
  46.  
  47.   // a brief delay, so this runs 250 times per second
  48.   delay(4);
  49. }
  50.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement