Guest User

Untitled

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