daily pastebin goal
33%
SHARE
TWEET

DanceForce V3 Teensy code (1.0)

PromitRoy Apr 9th, 2018 104 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //This is the LED pin for a Teensy LC, may need to change on other boards
  2. const int LedPin = 13;
  3. //The analog threshold value for triggering a button
  4. const int TriggerThreshold = 4;
  5.  
  6. void setup() {
  7.  
  8.   Serial.begin(38400);
  9.   pinMode(LedPin, OUTPUT);
  10.  
  11.   //The analog pins are configured with internal pull-up resistors, which makes for a very simple circuit
  12.   //However this method does not support useful pressure sensitivity adjustments
  13.   //By soldering 1K resistors as pull-ups on the board, you can make the buttons require more pressure
  14.   //The first version did that, but making the buttons more difficult didn't seem very desirable
  15.   pinMode(14, INPUT_PULLUP);
  16.   pinMode(16, INPUT_PULLUP);
  17.   pinMode(18, INPUT_PULLUP);
  18.   pinMode(20, INPUT_PULLUP);
  19.   pinMode(22, INPUT_PULLUP);
  20.   pinMode(23, INPUT_PULLUP);
  21. }
  22.  
  23. void loop() {
  24.   //pin mappings for where things got soldered
  25.   int p[6] = {0, 2, 4, 6, 8, 9};
  26.   //analog read values
  27.   int a[6] = {0};
  28.   //check if any buttons are pressed, so we know whether to light the LED
  29.   bool pressed = false;
  30.  
  31.   //read each pin, and set that Joystick button appropriately
  32.   for(int i = 0; i < 6; ++i)
  33.   {
  34.     a[i] = analogRead(p[i]);
  35.     if(a[i] < TriggerThreshold)
  36.     {
  37.       pressed = true;
  38.       Joystick.button(i+1, 1);
  39.     }
  40.     else
  41.     {
  42.       Joystick.button(i+1, 0);
  43.     }
  44.   }
  45.  
  46.   //Illuminate the LED if a button is pressed
  47.   if(pressed)
  48.     digitalWrite(LedPin, HIGH);
  49.   else
  50.     digitalWrite(LedPin, LOW);
  51.  
  52.   //Enable this block if you need to debug the electricals of the pad
  53.   if(0)
  54.   {
  55.     Serial.printf("Pins: %d %d %d %d (%d %d)\n", a[0], a[1], a[2], a[3], a[4], a[5]);
  56.     delay(250);
  57.   }
  58.  
  59.   //This limits the pad to run at 200 Hz. This version of the code does not debounce.
  60.   delay(5);
  61. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Pastebin PRO 'AUTUMN SPECIAL'!
Get 40% OFF Pastebin PRO accounts!
 
Top