Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********** Constantes **********/
- #define POT1 A0
- #define POT2 A1
- #define TOTLED 8 // Total LEDs
- /********** Objetos **********/
- // ninguno
- /********** Variables **********/
- int led[TOTLED] = {
- 2, 3, 4, 5, 6, 7, 8, 9};
- /********** Configuracion **********/
- void setup() {
- int pos=0;
- while (pos < TOTLED){
- pinMode(led[pos], OUTPUT);
- pos=pos+1;
- }
- pinMode(POT1, INPUT);
- pinMode(POT2, INPUT);
- } // end setup()
- /********** Ciclo Principal **********/
- void loop() {
- // Sensores
- int t_encendido = analogRead(POT1);
- int t_apagado = analogRead(POT2);
- // Acciones
- for (int pos = 0; pos < TOTLED; pos++) {
- int t_encendido = analogRead(POT1);
- int t_apagado = analogRead(POT2);
- on(led[pos], t_encendido);
- off(led[pos], t_apagado);
- }
- for (int pos = TOTLED-2; pos > 0; pos--) {
- int t_encendido = analogRead(POT1);
- int t_apagado = analogRead(POT2);
- on(led[pos], t_encendido);
- off(led[pos], t_apagado);
- }
- } // end loop()
- /********** Funciones **********/
- // Pone en +5V el pin indicado, durante tantos milisegundos
- void on(int pin, int ms){
- digitalWrite(pin, HIGH);
- delay(ms);
- } // end on()
- // Pone en GND el pin indicado, durante tantos milisegundos
- void off(int pin, int ms){
- digitalWrite(pin, LOW);
- delay(ms);
- } // end off()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement