Forked from catatonicTrepidation/Arduino Code Combinations
Last active
August 29, 2015 14:21
-
-
Save KaiaKitten/ad4b6f22b192b5cc9884 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 LED=9; | |
const int BUTTON1=2; | |
const int BUTTON2=3; | |
const String CODE = "ABAB"; | |
String rec = ""; | |
String lastRec = ""; | |
boolean lastButton1 = LOW; | |
boolean currentButton1 = LOW; | |
boolean lastButton2 = LOW; | |
boolean currentButton2 = LOW; | |
boolean ledOn = false; | |
void setup() { | |
Serial.begin(9600); | |
pinMode(LED,OUTPUT); | |
pinMode(BUTTON1,INPUT); | |
pinMode(BUTTON2,INPUT); | |
Serial.println("Hello World"); | |
} | |
boolean debounce(boolean last, int button) | |
{ | |
boolean current = digitalRead(button); | |
if(last != current) | |
{ | |
delay(5); | |
current = digitalRead(button); | |
} | |
return current; | |
} | |
void loop() { | |
currentButton1 = debounce(lastButton1,BUTTON1); | |
if(lastButton1 == LOW && currentButton1 == HIGH) | |
{ | |
rec+="A"; | |
} | |
lastButton1 = currentButton1; | |
currentButton2 = debounce(lastButton2,BUTTON2); | |
if(lastButton2 == LOW && currentButton2 == HIGH) | |
{ | |
rec+="B"; | |
} | |
lastButton2 = currentButton2; | |
if(rec.endsWith(CODE)) | |
{ | |
ledOn = true; | |
}else | |
{ | |
ledOn= false; | |
} | |
if(rec != "") | |
{ | |
if(lastRec != rec) //only output rec if there is a change | |
{ | |
Serial.println(rec); | |
lastRec = rec; | |
} | |
} | |
digitalWrite(LED,ledOn); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment