1 changed files with 72 additions and 0 deletions
@ -0,0 +1,72 @@ |
|||
|
|||
int langs[] = {2,3,4,5}; |
|||
int leds[] = {6,9,10,11}; |
|||
bool state[] = {0,0,0,0}; |
|||
int old = 0; |
|||
int current = 0; |
|||
|
|||
void setup() { |
|||
|
|||
Serial.begin(9600); |
|||
|
|||
for(int i=0; i<4; i++) { |
|||
pinMode(langs[i], INPUT); |
|||
pinMode(leds[i], OUTPUT); |
|||
} |
|||
} |
|||
|
|||
void loop() { |
|||
|
|||
checkStatus(); |
|||
|
|||
if(current == 0) { |
|||
for(int i=0; i<255; i++) { |
|||
checkStatus(); |
|||
for(int x=0; x<4; x++) { |
|||
analogWrite(leds[x], i); |
|||
} |
|||
delay(10); |
|||
} |
|||
for(int i=255; i>0; i--) { |
|||
checkStatus(); |
|||
for(int x=0; x<4; x++) { |
|||
analogWrite(leds[x], i); |
|||
} |
|||
delay(10); |
|||
} |
|||
} else { |
|||
for(int i=0; i<100; i++) { |
|||
checkStatus(); |
|||
if(current != 0) { |
|||
analogWrite(leds[current-1], i); |
|||
} |
|||
delay(10); |
|||
} |
|||
for(int i=100; i>0; i--) { |
|||
checkStatus(); |
|||
if(current != 0) { |
|||
analogWrite(leds[current-1], i); |
|||
} |
|||
delay(10); |
|||
} |
|||
} |
|||
} |
|||
|
|||
|
|||
void checkStatus() { |
|||
|
|||
current = 0; |
|||
for(int i=0; i<4; i++) { |
|||
state[i] = digitalRead(langs[i]); |
|||
//Serial.print(state[i]);
|
|||
//Serial.print("\t");
|
|||
if(state[i] == LOW) { |
|||
current = i+1; |
|||
} |
|||
} |
|||
|
|||
if(old != current) { |
|||
old = current; |
|||
Serial.println(current); |
|||
} |
|||
} |
Loading…
Reference in new issue