Working Switch
Creative design
Code:
const int left = 2;
const int right = 3;
const int up =4;
const int down = 5;
const int a =6;
const int b =7;
const int red =13;
const int green =12;
const int blue =11;
int L;
int R;
int U;
int D;
int A;
int B;
int len;
String input;
String temp;
String code = "uuddlrlrba";
//run this once
void setup(){
Serial.begin(9600);
pinMode(left,INPUT);
pinMode(right,INPUT);
pinMode(up,INPUT);
pinMode(down,INPUT);
pinMode(a,INPUT);
pinMode(b,INPUT);
pinMode(red,OUTPUT);
pinMode(green,OUTPUT);
pinMode(blue,OUTPUT);
input="";
}
void loop(){
len = input.length();
digitalWrite(green,LOW);
digitalWrite(red,LOW);
digitalWrite(blue,LOW);
L = digitalRead(left);
R = digitalRead(right);
U = digitalRead(up);
D = digitalRead(down);
A = digitalRead(a);
B = digitalRead(b);
if(U==HIGH){
digitalWrite(red,HIGH);
delay(250);
temp+= 'u';
}
else if(D==HIGH){
digitalWrite(red,HIGH);
delay(250);
temp+= 'd';
}
else if(L==HIGH){
digitalWrite(red,HIGH);
delay(250);
temp+= 'l';
}
else if(R==HIGH){
digitalWrite(red,HIGH);
delay(250);
temp+= 'r';
}
else if(A==HIGH){
digitalWrite(red,HIGH);
delay(250);
temp+= 'a';
}
else if(B==HIGH){
digitalWrite(red,HIGH);
delay(250);
temp+= 'b';
}
if(temp.compareTo("")!=0){
input +=temp.charAt(0);
Serial.println("check");
temp="";
}
if(input.compareTo(code)==0){
digitalWrite(blue, HIGH);
}
Serial.println(input);
No comments:
Post a Comment