Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //This is the LED pin for a Teensy LC, may need to change on other boards
- const int LedPin = 13;
- //The analog threshold value for triggering a button
- const int TriggerThreshold = 4;
- void setup() {
- Serial.begin(38400);
- pinMode(LedPin, OUTPUT);
- //The analog pins are configured with internal pull-up resistors, which makes for a very simple circuit
- //However this method does not support useful pressure sensitivity adjustments
- //By soldering 1K resistors as pull-ups on the board, you can make the buttons require more pressure
- //The first version did that, but making the buttons more difficult didn't seem very desirable
- pinMode(14, INPUT_PULLUP);
- pinMode(16, INPUT_PULLUP);
- pinMode(18, INPUT_PULLUP);
- pinMode(20, INPUT_PULLUP);
- pinMode(22, INPUT_PULLUP);
- pinMode(23, INPUT_PULLUP);
- }
- void loop() {
- //pin mappings for where things got soldered
- int p[6] = {0, 2, 4, 6, 8, 9};
- //analog read values
- int a[6] = {0};
- //check if any buttons are pressed, so we know whether to light the LED
- bool pressed = false;
- //read each pin, and set that Joystick button appropriately
- for(int i = 0; i < 6; ++i)
- {
- a[i] = analogRead(p[i]);
- if(a[i] < TriggerThreshold)
- {
- pressed = true;
- Joystick.button(i+1, 1);
- }
- else
- {
- Joystick.button(i+1, 0);
- }
- }
- //Illuminate the LED if a button is pressed
- if(pressed)
- digitalWrite(LedPin, HIGH);
- else
- digitalWrite(LedPin, LOW);
- //Enable this block if you need to debug the electricals of the pad
- if(0)
- {
- Serial.printf("Pins: %d %d %d %d (%d %d)\n", a[0], a[1], a[2], a[3], a[4], a[5]);
- delay(250);
- }
- //This limits the pad to run at 200 Hz. This version of the code does not debounce.
- delay(5);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement