Advertisement
Guest User

laboratori2

a guest
Sep 22nd, 2016
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.35 KB | None | 0 0
  1. /********** Constantes **********/
  2.  
  3. #define POT1    A0
  4. #define POT2    A1
  5. #define TOTLED   8 // Total LEDs
  6.  
  7. /********** Objetos **********/
  8.  
  9. // ninguno
  10.  
  11. /********** Variables **********/
  12.  
  13. int led[TOTLED] = {
  14.   2, 3, 4, 5, 6, 7, 8, 9};
  15.  
  16. /********** Configuracion **********/
  17.  
  18. void setup() {
  19.   int pos=0;
  20.   while (pos < TOTLED){
  21.     pinMode(led[pos], OUTPUT);
  22.     pos=pos+1;
  23.   }
  24.   pinMode(POT1, INPUT);
  25.   pinMode(POT2, INPUT);
  26. } // end setup()
  27.  
  28. /********** Ciclo Principal **********/
  29.  
  30. void loop() {
  31.  
  32.   // Sensores
  33.   int t_encendido = analogRead(POT1);
  34.   int t_apagado = analogRead(POT2);
  35.  
  36.   // Acciones
  37.   for (int pos = 0; pos < TOTLED; pos++) {
  38.     int t_encendido = analogRead(POT1);
  39.   int t_apagado = analogRead(POT2);
  40.     on(led[pos], t_encendido);  
  41.     off(led[pos], t_apagado);  
  42.   }
  43.   for (int pos = TOTLED-2; pos > 0; pos--) {
  44.     int t_encendido = analogRead(POT1);
  45.   int t_apagado = analogRead(POT2);
  46.     on(led[pos], t_encendido);  
  47.     off(led[pos], t_apagado);  
  48.   }
  49.  
  50. } // end loop()
  51.  
  52. /********** Funciones **********/
  53.  
  54. // Pone en +5V el pin indicado, durante tantos milisegundos
  55. void on(int pin, int ms){
  56.   digitalWrite(pin, HIGH);  
  57.   delay(ms);  
  58. } // end on()
  59.  
  60. // Pone en GND el pin indicado, durante tantos milisegundos
  61. void off(int pin, int ms){
  62.   digitalWrite(pin, LOW);  
  63.   delay(ms);  
  64. } // end off()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement