6 changed files with 172 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); |
||||
|
} |
||||
|
} |
@ -0,0 +1,100 @@ |
|||||
|
|
||||
|
int langs[] = {2,4,7,8}; |
||||
|
int leds[] = {6,9,10,11}; |
||||
|
int triggerPin = 12; |
||||
|
int tracePin = 3; |
||||
|
|
||||
|
bool langStatus[] = {0,0,0,0}; |
||||
|
int oldLang = 0; |
||||
|
int currentLang = 0; |
||||
|
|
||||
|
bool oldTrigger = 0; |
||||
|
bool trigger = 0; |
||||
|
|
||||
|
int traceStatus = 0; |
||||
|
|
||||
|
void setup() { |
||||
|
|
||||
|
Serial.begin(9600); |
||||
|
|
||||
|
for(int i=0; i<4; i++) { |
||||
|
pinMode(langs[i], INPUT); |
||||
|
pinMode(leds[i], OUTPUT); |
||||
|
} |
||||
|
pinMode(triggerPin, INPUT); |
||||
|
pinMode(tracePin, OUTPUT); |
||||
|
|
||||
|
for(int i=0; i<255; i++) { |
||||
|
analogWrite(tracePin, i); |
||||
|
delay(10); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
void loop() { |
||||
|
|
||||
|
trigger = digitalRead(triggerPin); |
||||
|
|
||||
|
if(oldTrigger != trigger) { |
||||
|
oldTrigger = trigger; |
||||
|
|
||||
|
if(trigger == HIGH) { |
||||
|
checkLang(); |
||||
|
Serial.print("speech"); |
||||
|
Serial.print("\t"); |
||||
|
Serial.println(currentLang); |
||||
|
|
||||
|
for(int i=traceStatus; i>=0; i--) { |
||||
|
analogWrite(tracePin, i); |
||||
|
delay(5); |
||||
|
} |
||||
|
for(int i=0; i<1000; i++) { |
||||
|
analogWrite(leds[0], constrain(i,0,255)); |
||||
|
analogWrite(leds[1], constrain(i-100, 0, 255)); |
||||
|
analogWrite(leds[2], constrain(i-300, 0, 255)); |
||||
|
analogWrite(leds[3], constrain(i-600, 0, 255)); |
||||
|
delay(5); |
||||
|
} |
||||
|
} else { |
||||
|
for(int i=255; i>=0; i--) { |
||||
|
checkLang(); |
||||
|
for(int x=0; x<4; x++) { |
||||
|
analogWrite(leds[x], i); |
||||
|
} |
||||
|
delay(10); |
||||
|
} |
||||
|
|
||||
|
while(oldTrigger == trigger) { |
||||
|
trigger = digitalRead(triggerPin); |
||||
|
for(traceStatus=0; traceStatus<255; traceStatus++) { |
||||
|
analogWrite(tracePin, traceStatus); |
||||
|
delay(10); |
||||
|
} |
||||
|
trigger = digitalRead(triggerPin); |
||||
|
for(traceStatus=255; traceStatus>0; traceStatus--) { |
||||
|
analogWrite(tracePin, traceStatus); |
||||
|
delay(10); |
||||
|
} |
||||
|
trigger = digitalRead(triggerPin); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
void checkLang() { |
||||
|
|
||||
|
currentLang = 0; |
||||
|
for(int i=0; i<4; i++) { |
||||
|
langStatus[i] = digitalRead(langs[i]); |
||||
|
//Serial.print(langStatus[i]);
|
||||
|
//Serial.print("\t");
|
||||
|
if(langStatus[i] == LOW) { |
||||
|
currentLang = i+1; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
if(oldLang != currentLang) { |
||||
|
oldLang = currentLang; |
||||
|
//Serial.println(currentLang);
|
||||
|
} |
||||
|
} |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in new issue