#define SENSOR_PIN A0 / / analógico entrada de pin para la música
void showScenario(int);
siguiente escenario de gatillo cuando amplitud música > umbral
aumentar el umbral para disminuir la sensibilidad
disminuir el umbral para aumentar la sensibilidad
int umbral = 5;
contra rebotes - filtrar consecutivos desencadenadores que están demasiado cercanas
para ralentizar la animación. disminuir este valor
para que sea más sensible a la menor intervalos beats
int minBeatInterval = 1000;
int threshCrossed = 0;
escenario de int = 1;
int cnt = 32768;
tree1 int = 6;
tree2 int = 7;
int tree3 = 8;
int tree4 = 9;
int tree5 = 2;
int tree6 = 3;
int tree7 = 4;
int tree8 = 5;
void setup()
{
pinMode (tree1, salida);
pinMode (tree2, salida);
pinMode (tree3, salida);
pinMode (tree4, salida);
pinMode (tree5, salida);
pinMode (tree6, salida);
pinMode (tree7, salida);
pinMode (tree8, salida);
digitalWrite(tree1,HIGH);
Delay(1000);
digitalWrite(tree2,HIGH);
Delay(1000);
digitalWrite(tree3,HIGH);
Delay(1000);
digitalWrite(tree4,HIGH);
Delay(1000);
digitalWrite(tree5,HIGH);
Delay(1000);
digitalWrite(tree6,HIGH);
Delay(1000);
digitalWrite(tree7,HIGH);
Delay(1000);
digitalWrite(tree8,HIGH);
Delay(1000);
digitalWrite(tree1,LOW);
digitalWrite(tree2,LOW);
digitalWrite(tree3,LOW);
digitalWrite(tree4,LOW);
digitalWrite(tree5,LOW);
digitalWrite(tree6,LOW);
digitalWrite(tree7,LOW);
digitalWrite(tree8,LOW);
Serial.Begin(9600);
}
void showScenario (int s) {}
int theScenario;
theScenario = s;
Si (theScenario == 1) {}
digitalWrite (tree1, LOW);
digitalWrite (tree8, bajo);
digitalWrite (tree1, HIGH);
digitalWrite (tree3, HIGH);
}
Si (theScenario == 2) {}
digitalWrite (tree1, LOW);
digitalWrite (tree3, bajo);
digitalWrite (tree6, HIGH);
digitalWrite (tree8, HIGH);
}
Si (theScenario == 3) {}
digitalWrite (tree6, bajo);
digitalWrite (tree8, bajo);
digitalWrite (tree3, HIGH);
digitalWrite (tree4, HIGH);
}
Si (theScenario == 4) {}
digitalWrite (tree3, bajo);
digitalWrite (tree4, bajo);
digitalWrite (tree5, HIGH);
digitalWrite (tree6, HIGH);
}
Si (theScenario == 5)
{digitalWrite (tree5, bajo);
digitalWrite (tree6, bajo);
digitalWrite (tree3, HIGH);
digitalWrite (tree4, HIGH);
}
Si (theScenario == 6) {}
digitalWrite (tree3, bajo);
digitalWrite (tree4, bajo);
digitalWrite (tree5, HIGH);
digitalWrite (tree6, HIGH);
}
Si (theScenario == 7) {}
digitalWrite (tree5, bajo);
digitalWrite (tree6, bajo);
digitalWrite (tree1, HIGH);
digitalWrite (tree3, HIGH);
}
Si (theScenario == 8) {}
digitalWrite (tree1, LOW);
digitalWrite (tree3, bajo);
digitalWrite (tree2, HIGH);
digitalWrite (tree4, HIGH);
}
Si (theScenario == 9) {}
digitalWrite (tree2, LOW);
digitalWrite (tree4, bajo);
digitalWrite (tree3, HIGH);
digitalWrite (tree5, HIGH);
}
Si (theScenario == 10) {}
digitalWrite (tree3, bajo);
digitalWrite (tree5, bajo);
digitalWrite (tree4, HIGH);
digitalWrite (tree6, HIGH);
}
Si (theScenario == 11) {}
digitalWrite (tree4, bajo);
digitalWrite (tree6, bajo);
digitalWrite (tree5, HIGH);
digitalWrite (tree7, HIGH);
}
Si (theScenario == 12) {}
digitalWrite (tree5, bajo);
digitalWrite (tree7, bajo);
digitalWrite (tree6, HIGH);
digitalWrite (tree8, HIGH);
}
Si (theScenario == 13) {}
digitalWrite (tree6, bajo);
digitalWrite (tree8, bajo);
digitalWrite (tree1, HIGH);
digitalWrite (tree4, HIGH);
}
Si (theScenario == 14) {}
digitalWrite (tree1, LOW);
digitalWrite (tree4, bajo);
digitalWrite (tree5, HIGH);
digitalWrite (tree8, HIGH);
}
Si (theScenario == 15) {}
digitalWrite (tree5, bajo);
digitalWrite (tree8, bajo);
digitalWrite (tree2, HIGH);
digitalWrite (tree4, HIGH);
}
Si (theScenario == 16) {}
digitalWrite (tree2, LOW);
digitalWrite (tree4, bajo);
digitalWrite (tree5, HIGH);
digitalWrite (tree7, HIGH);
}
Si (theScenario == 17) {}
digitalWrite (tree5, bajo);
digitalWrite (tree7, bajo);
digitalWrite (tree1, HIGH);
}
Si (theScenario == 18) {}
digitalWrite (tree1, LOW);
digitalWrite (tree2, HIGH);
}
Si (theScenario == 19) {}
digitalWrite (tree2, LOW);
digitalWrite (tree3, HIGH);
}
Si (theScenario == 20) {}
digitalWrite (tree3, bajo);
digitalWrite (tree2, HIGH);
digitalWrite (tree4, HIGH);
}
Si (theScenario == 21) {}
digitalWrite (tree2, LOW);
digitalWrite (tree4, bajo);
digitalWrite (tree3, HIGH);
}
Si (theScenario == 22) {}
digitalWrite (tree3, bajo);
digitalWrite (tree4, HIGH);
}
Si (theScenario == 23) {}
digitalWrite (tree4, bajo);
digitalWrite (tree3, HIGH);
digitalWrite (tree5, HIGH);
}
Si (theScenario == 24) {}
digitalWrite (tree3, bajo);
digitalWrite (tree5, bajo);
digitalWrite (tree4, HIGH);
}
Si (theScenario == 25) {}
digitalWrite (tree4, bajo);
digitalWrite (tree5, HIGH);
}
Si (theScenario == 26) {}
digitalWrite (tree5, bajo);
digitalWrite (tree4, HIGH);
digitalWrite (tree6, HIGH);
}
Si (theScenario == 27) {}
digitalWrite (tree4, bajo);
digitalWrite (tree6, bajo);
digitalWrite (tree5, HIGH);
}
Si (theScenario == 28) {}
digitalWrite (tree5, bajo);
digitalWrite (tree6, HIGH);
}
Si (theScenario == 29) {}
digitalWrite (tree6, bajo);
digitalWrite (tree5, HIGH);
digitalWrite (tree7, HIGH);
}
Si (theScenario == 30) {}
digitalWrite (tree5, bajo);
digitalWrite (tree7, bajo);
digitalWrite (tree6, HIGH);
}
Si (theScenario == 31) {}
digitalWrite (tree6, bajo);
digitalWrite (tree7, HIGH);
}
Si (theScenario == 32) {}
digitalWrite (tree7, bajo);
digitalWrite (tree8, HIGH);
}
Si (theScenario == 33) {}
digitalWrite (tree8, bajo);
digitalWrite (tree4, HIGH);
digitalWrite (tree5, HIGH);
}
Si (theScenario == 34) {}
digitalWrite (tree4, bajo);
digitalWrite (tree5, bajo);
digitalWrite (tree3, HIGH);
digitalWrite (tree6, HIGH);
}
Si (theScenario == 35) {}
digitalWrite (tree3, bajo);
digitalWrite (tree6, bajo);
digitalWrite (tree2, HIGH);
digitalWrite (tree7, HIGH);
}
Si (theScenario == 36) {}
digitalWrite (tree2, LOW);
digitalWrite (tree7, bajo);
digitalWrite (tree1, HIGH);
digitalWrite (tree8, HIGH);
}
Si (theScenario == 37) {}
digitalWrite (tree1, LOW);
digitalWrite (tree8, bajo);
digitalWrite (tree4, HIGH);
digitalWrite (tree5, HIGH);
}
Si (theScenario == 38) {}
digitalWrite (tree4, bajo);
digitalWrite (tree5, bajo);
digitalWrite (tree3, HIGH);
digitalWrite (tree6, HIGH);
}
Si (theScenario == 39) {}
digitalWrite (tree3, bajo);
digitalWrite (tree6, bajo);
digitalWrite (tree2, HIGH);
digitalWrite (tree7, HIGH);
}
Si (theScenario == 40) {}
digitalWrite (tree2, LOW);
digitalWrite (tree7, bajo);
digitalWrite (tree1, HIGH);
digitalWrite (tree8, HIGH);
}
} void loop() {}
int sensorValue = analogRead(SENSOR_PIN);
CNT ++;
Si (sensorValue > umbral) {}
Si (! threshCrossed & & (cnt > minBeatInterval)) {}
showScenario(scenario);
escenario ++;
}
Si {} (escenario > 40)
escenario = 1;
}
threshCrossed = 1;
CNT = 0;
}
Si (sensorValue < umbral) {}
threshCrossed = 0;
}
}