Created
June 10, 2017 03:46
-
-
Save JCharante/a347906d92ccf5d82e4589f067f78a2b 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
const int ledPin = 13; | |
const int button1Pin = 2; | |
const int button2Pin = 3; | |
const int button3Pin = 4; | |
class Melody { | |
int pattern [7] = {1, 1, 2, 2, 3, 3, 2}; | |
int inputs [7] = {0, 0, 0, 0, 0, 0, 0}; | |
public: | |
int onInput (int buttonNum) { | |
inputs[sizeof(inputs)] = buttonNum; | |
bool mismatch; | |
for (int i = 0; i < sizeof(inputs); i++) { | |
if (inputs[i] != pattern[i]) { | |
mismatch = true; | |
} | |
} | |
if (mismatch) { | |
inputs[0] = 0; | |
inputs[1] = 0; | |
inputs[2] = 0; | |
inputs[3] = 0; | |
inputs[4] = 0; | |
inputs[5] = 0; | |
inputs[6] = 0; | |
return 1; | |
} | |
return 0; | |
} | |
}; | |
Melody melody; | |
int button1State = 0; | |
int button2State = 0; | |
int button3State = 0; | |
int prevButton1State; | |
int prevButton2State; | |
int prevButton3State; | |
void setup() { | |
pinMode(ledPin, OUTPUT); | |
pinMode(button1Pin, INPUT); | |
pinMode(button2Pin, INPUT); | |
pinMode(button3Pin, INPUT); | |
digitalWrite(ledPin, LOW); | |
Serial.begin(9600); | |
} | |
void loop() { | |
// put your main code here, to run repeatedly: | |
button1State = digitalRead(button1Pin); | |
button2State = digitalRead(button2Pin); | |
button3State = digitalRead(button3Pin); | |
Serial.println("Start Loop"); | |
Serial.println(""); | |
if (button1State == HIGH && prevButton1State == 0){ | |
Serial.print(1); | |
if (melody.onInput(1) == 0) { | |
digitalWrite(ledPin, HIGH); | |
Serial.println("LED On"); | |
} | |
} | |
if (button2State == HIGH && prevButton2State == 0){ | |
Serial.print(2); | |
if (melody.onInput(2) == 0) { | |
digitalWrite(ledPin, HIGH); | |
Serial.println("LED On"); | |
} | |
} | |
if (button3State == HIGH && prevButton3State == 0){ | |
Serial.print(3); | |
if (melody.onInput(3) == 0) { | |
digitalWrite(ledPin, HIGH); | |
Serial.println("LED On"); | |
} | |
} | |
prevButton1State = button1State; | |
prevButton2State = button2State; | |
prevButton3State = button3State; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Working on abstracting the keyboard stuff