Skip to content

Instantly share code, notes, and snippets.

@zach-c-d
Last active September 16, 2017 18:51
Show Gist options
  • Save zach-c-d/fd72937a151ea344973583571965b798 to your computer and use it in GitHub Desktop.
Save zach-c-d/fd72937a151ea344973583571965b798 to your computer and use it in GitHub Desktop.
/*
#### # #### ##### ## # ####
# # # # # # # # # # #
# # # # ##### # # # ####
# ### # # # # # ###### # #
# # # # # # # # # # # #
#### ###### #### ##### # # ###### ####
*/
//pressure on pad where hit is registered
int hitThreshold = 780;
//milliseconds that LED is lit for
int lightDelay = 300;
//stores last update time
unsigned long previousMillis;
unsigned long currentMillis;
//pad and led pin info
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 };
//stores last combo input
int input_combo[] = {};
/*
#####
# # # ## #### ####
# # # # # #
# # # # #### ####
# # ###### # #
# # # # # # # # #
##### ###### # # #### ####
*/
class Pad{
//object variables
int padPin;
int ledPin;
//variables that maintain current state
int ledState; //store HIGH/LOW of LED
//initializes the object
public:
Pad(int pad, int led){
padPin = pad;
ledPin = led;
pinMode(ledPin, OUTPUT);
pinMode(padPin, INPUT);
ledState = LOW;
previousMillis = 0;
}
//object functions
void Update(){
checkPad();
dimLED();
}
bool checkPad(){
int padReading = analogRead(padPin);
if (padReading >= hitThreshold){
previousMillis = millis(); //record time
lightLED();//light the led
//add pad to end of input_combo
input_combo[sizeof(input_combo)] = padPin;
return true;
}else{
return false;
}
}
void lightLED(){
ledState = HIGH; //update ledState
digitalWrite(ledPin, ledState); //update LED
previousMillis = millis(); //record time
}
void dimLED(){
currentMillis = millis();
//if led is lit, and last update was longer than lightDelay ago, turn led off
if((ledState == HIGH) && (currentMillis >= previousMillis + lightDelay)){
ledState = LOW; //update ledState
digitalWrite(ledPin, ledState); //update led
}
}
};
//instatiate the game pads
//(pad, led)
Pad pad_center(centerPad, centerLED);
Pad pad_right(rightPad, rightLED);
Pad pad_bottom(bottomPad, bottomLED);
Pad pad_left(leftPad, leftLED);
void setup(){
Serial.begin(9600);
}
void loop(){
pad_center.Update();
pad_right.Update();
pad_bottom.Update();
pad_left.Update();
}
void chooseCombo(){
}
void showCombo(int combo){
for(i = 0; i < sizeof(combo); i++){
}
}
int combo123[] = { centerPad, centerPad, leftPad};
int combo234[] = {centerPad, leftPad, rightPad};
int combo342[] = {leftPad, rightPad, centerPad};
int combo1256[] = {leftPad, leftPad, bottomPad, bottomPad};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment