You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
72 lines
1.2 KiB
72 lines
1.2 KiB
|
|
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);
|
|
}
|
|
}
|