Last active
February 21, 2022 13:17
-
-
Save RaymarMonte/7c7f8191564515b28eeb5545048630d1 to your computer and use it in GitHub Desktop.
Code for the Arduino Leonardo that controls the dance pad. Dance pad was built following the guidelines of Danceforce v3 and v4 by Promit at https://ventspace.wordpress.com/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Gamepad.h> | |
// Gamepad initialization | |
Gamepad gp; | |
const int ledPin = 13; | |
// Buttons | |
const int up = A3; | |
const int start = A1; | |
const int right = A0; | |
const int down = A6; | |
const int left = A8; | |
const int back = A9; | |
const int buttons[6] = {up, down, left, right, start, back}; | |
const int thresholds[6] = {18, 20, 20, 18, 18, 18}; | |
void setup() { | |
Serial.begin(38400); | |
pinMode(ledPin, OUTPUT); | |
for (int i = 0;i < sizeof(buttons); i++) { | |
pinMode(buttons[i], INPUT_PULLUP); | |
} | |
} | |
void loop() { | |
bool buttonPressed = false; | |
int analogReads[6] = {0}; | |
for (int i = 0;i < 6;i++) { | |
analogReads[i] = analogRead(buttons[i]); | |
if (analogReads[i] <= thresholds[i]) { | |
buttonPressed = true; | |
gp.setButtonState(i, true); | |
} | |
else { | |
gp.setButtonState(i, false); | |
} | |
} | |
if (buttonPressed) { | |
digitalWrite(ledPin, HIGH); | |
} | |
else { | |
digitalWrite(ledPin, LOW); | |
} | |
if (0) { | |
for (int i = 0;i < 6;i++) { | |
if (analogReads[i] < 21) { | |
String debug = "up: " + String(analogReads[0]) + " down: " + | |
String(analogReads[1]) + " left: " + String(analogReads[2]) + | |
" right: " + String(analogReads[3]) + " start: " + String(analogReads[4]) + | |
" back: " + String(analogReads[5]); | |
Serial.println(debug); | |
break; | |
} | |
} | |
// delay(250); | |
} | |
delay(5); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment