Created
September 13, 2017 20:53
-
-
Save zach-c-d/0fe90cca4efa0c45b2e95ea526c8ac0c to your computer and use it in GitHub Desktop.
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
int centerPad = A0; | |
int rightPad = A1; | |
int bottomPad = A3; | |
int leftPad = A5; | |
int centerLED = 2; | |
int rightLED = 3; | |
int bottomLED = 4; | |
int leftLED = 7; | |
int sensors[] = { centerPad, rightPad, bottomPad, leftPad }; | |
int LEDs[] = { centerLED, rightLED, bottomLED, leftLED }; | |
int hitThreshold = 775; | |
int lightDelay = 300; | |
void setup() { | |
delay(100); | |
pinMode(centerPad, INPUT); | |
pinMode(rightPad, INPUT); | |
pinMode(bottomPad, INPUT); | |
pinMode(leftPad, INPUT); | |
pinMode(centerLED, OUTPUT); | |
pinMode(rightLED, OUTPUT); | |
pinMode(bottomLED, OUTPUT); | |
pinMode(leftLED, OUTPUT); | |
digitalWrite(centerLED, LOW); | |
digitalWrite(rightLED, LOW); | |
digitalWrite(bottomLED, LOW); | |
digitalWrite(leftLED, LOW); | |
Serial.begin(9600); | |
} | |
void loop(){ | |
// workPad(); | |
// while(workPad() == false){ | |
// DoubleJab(); | |
// if(workPad() == true){ | |
// break; | |
// } | |
// } | |
workPad(); | |
} | |
void runLEDs(){ | |
for(int i = 0; i < 4; i++){ | |
digitalWrite(LEDs[i], HIGH); | |
delay(200); | |
digitalWrite(LEDs[i], LOW); | |
} | |
} | |
void lightLED(int LED){ //Light LED for 0.3 seconds | |
unsigned long previousMillis = millis(); //will store last time LED was updated | |
unsigned long currentMillis = millis(); //record current time | |
//while current millis is less than lightLED start + lightDelay | |
while(currentMillis >! previousMillis + lightDelay){ | |
digitalWrite(LED, HIGH); | |
currentMillis = millis(); | |
//check if currentMillis is greater than previous + lightDelay | |
if(currentMillis >= previousMillis + lightDelay){ | |
break; | |
} | |
} | |
//after break, turn off LED | |
digitalWrite(LED, LOW); | |
//previousMillis = currentMillis; | |
} | |
boolean workPad(){ | |
for(int i = 0; i < 4; i++){ | |
int reading = analogRead(sensors[i]); | |
if(reading > hitThreshold){ | |
lightLED(LEDs[i]); | |
return(true); | |
} | |
} | |
} | |
///////////COMBOS//////////// | |
void DoubleJab(){ | |
int doubleJab[] = { centerPad, centerPad }; | |
for (int i = 0; i < sizeof(doubleJab); i++){ | |
lightLED(LEDs[i]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment