augusto0112

lab3.0

Oct 23rd, 2016
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.47 KB | None | 0 0
  1. /********** Arduino **********
  2.  * Laboratorio 03: 8 LEDs en linea controlados con Processing
  3.  * Autor: Cristian Augusto Restrepo
  4.  * Descripcion:
  5.  *   Controlar 8 LEDs desde el Arduino, un LED encendido que se mueve en forma continua de izquierda a derecha,
  6.  *   vía una interfaz gráfica en Processing/ControlP5 para controlar el tiempo de encendido y el tiempo de apagado.
  7.  
  8. #define maxleds 8  
  9.  
  10. int t1=0;        
  11. int t2=0;        
  12. int valor=0;      
  13.  
  14. int led[maxleds] = { 2,3,4,5,6,7,8,9};
  15.  
  16. int i;          
  17. void setup ()
  18. {
  19.   Serial.begin(9600);
  20.   for (int i=0;i<maxleds;i++)
  21.     pinMode(led[i],OUTPUT);
  22. }
  23.  
  24. void loop()
  25. {
  26.  
  27.  
  28.   for (int i=0;i<=maxleds;i++)
  29.   {
  30.     if (Serial.available()>0)
  31.     {
  32.       valor = Serial.read();
  33.       if (valor == 'P')
  34.         t1 = Serial.parseInt();
  35.       if (valor == 'A')
  36.         t2 = Serial.parseInt();
  37.       Serial.write(t1);
  38.       Serial.write(t2);
  39.     }
  40.     prender(led[i],t1);
  41.     apagar(led[i],t2);
  42.   }
  43.  
  44.   for (int i=maxleds;i>=0;i--)
  45.   {
  46.     if (Serial.available()>0)
  47.     {
  48.       valor = Serial.read();
  49.       if (valor == 'O')
  50.         t1 = Serial.parseInt();
  51.       if (valor == 'F')
  52.         t2 = Serial.parseInt();
  53.       Serial.write(t1);
  54.       Serial.write(t2);
  55.     }
  56.     prender(led[i],t1);  
  57.     apagar(led[i],t2);  
  58.   }
  59. }
  60.  
  61. void prender(int i, int t)
  62. {
  63.   digitalWrite(i, HIGH);
  64.   delay(t);            
  65. }
  66.  
  67. void apagar(int i, int t)
  68. {
  69.   digitalWrite(i, LOW);
  70.   delay(t);            
  71. }
Advertisement
Add Comment
Please, Sign In to add comment