augusto0112

lab2

Oct 23rd, 2016
327
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.79 KB | None | 0 0
  1. /********** Proyecto **********
  2.  * Laboratorio 02: 8 LEDs en linea controlados con Potenciometros
  3.  * Autor: Diego Fernando Marin
  4.  * Edita: Cristian Augusto Restrepo
  5.  * Descripcion:
  6.  *   Mover un LED encendido de Izquierda a Derecha y viceversa
  7.  *   con tiempos controlados por potenciometros
  8.  * Conexiones:
  9.  *   8 LEDs + resistencias a los pines D2 .. D9
  10.  *   2 Potenciometros a los pines A0 y A1
  11.  * Version: 1
  12.  */
  13.  
  14. /********** Librerias **********/
  15.  
  16. // ninguna
  17.  
  18. /********** Constantes **********/
  19.  
  20. #define POT1    A0
  21. #define POT2    A1
  22. #define TOTLED   8 // Total LEDs
  23.  
  24. /********** Objetos **********/
  25.  
  26. // ninguno
  27.  
  28. /********** Variables **********/
  29.  
  30. int led[TOTLED] = {
  31.   2, 3, 4, 5, 6, 7, 8, 9};
  32.  
  33. /********** Configuracion **********/
  34.  
  35. void setup() {
  36.   int pos=0;
  37.   while (pos < TOTLED){
  38.     pinMode(led[pos], OUTPUT);
  39.     pos=pos+1;
  40.   }
  41.   pinMode(POT1, INPUT);
  42.   pinMode(POT2, INPUT);
  43. } // end setup()
  44.  
  45. /********** Ciclo Principal **********/
  46.  
  47. void loop() {
  48.  
  49.   // Acciones
  50.   for (int pos = 0; pos < TOTLED; pos++) {
  51.     int t_encendido = analogRead(POT1);
  52.     int t_apagado = analogRead(POT2);
  53.    
  54.     on(led[pos], t_encendido);  
  55.     off(led[pos], t_apagado);  
  56.   }
  57.   for (int pos = TOTLED-2; pos > 0; pos--) {
  58.     int t_encendido = analogRead(POT1);
  59.     int t_apagado = analogRead(POT2);
  60.    
  61.     on(led[pos], t_encendido);  
  62.     off(led[pos], t_apagado);  
  63.   }
  64.  
  65. } // end loop()
  66.  
  67. /********** Funciones **********/
  68.  
  69. // Pone en +5V el pin indicado, durante tantos milisegundos
  70. void on(int pin, int ms){
  71.   digitalWrite(pin, HIGH);  
  72.   delay(ms);  
  73. } // end on()
  74.  
  75. // Pone en GND el pin indicado, durante tantos milisegundos
  76. void off(int pin, int ms){
  77.   digitalWrite(pin, LOW);  
  78.   delay(ms);  
  79. } // end off()
  80.  
  81. /********** Fin ***********/
Advertisement
Add Comment
Please, Sign In to add comment