|
|
| Ho aggiunto un buzzer sul pin 7 e un vibratore preso da un joystick di play 2 sull'11. Non ho ancora rivisitato il source perché non ho tempo, ma così funziona: CODICE int count = 0; int lim = 5; int res[5]; int acc; int accp = 1; int note[] = {261, 294, 330, 349, 392, 440, 494, 523}; int nowp;
void light(int num = 0) { digitalWrite(3, LOW); digitalWrite(4, LOW); digitalWrite(5, LOW); digitalWrite(num, HIGH); }
void right() { digitalWrite(3, HIGH); digitalWrite(4, HIGH); digitalWrite(5, HIGH); delay(1000); light(); }
void start() { light(3); delay(100); light(4); delay(100); light(5); delay(100); light(); }
void error() { digitalWrite(11, 2); start(); digitalWrite(11, LOW); }
void check(int numButton) { if (res[count - 6] == numButton - 5) { noTone(7); tone(7, note[10 - count]); nowp = millis(); light(numButton - 5); count++; accp = acc; } else { noTone(7); error(); count = lim + 1; accp = 0; } }
void setup() { //Serial.begin(9600); pinMode(3, OUTPUT); pinMode(4, OUTPUT); pinMode(5, OUTPUT); pinMode(8, INPUT); pinMode(9, INPUT); pinMode(10, INPUT); pinMode(11, OUTPUT); pinMode(7, OUTPUT); randomSeed(analogRead(0)); }
void loop() { if (count < lim) { tone(7, note[count]); int acc = random(3, 6); if (acc != accp) { light(acc); res[count] = acc; accp = acc; count++; delay(500); noTone(7); } } else if (count == lim) { tone(7, note[count]); light(); delay(500); noTone(7); start(); delay(500); light(); count++; } else if (count < 2 * lim + 1) { if (millis() - nowp > 500) { noTone(7); } if (digitalRead(8)) { acc = 8; if (acc != accp) { check(8); } } if (digitalRead(9)) { acc = 9; if (acc != accp) { check(9); } } if (digitalRead(10)) { acc = 10; if (acc != accp) { check(10); } } } else { right(); noTone(7); delay(500); light(); delay(500); right(); delay(500); light(); delay(50000); digitalWrite(11, HIGH); delay(100); digitalWrite(11, LOW); } }
|
| |