Advertisement
Josueco

Lab4

Mar 24th, 2015
337
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.28 KB | None | 0 0
  1.  /********** Proyecto **********
  2.  * Laboratorio 4
  3.  * Autor: Josue Mauricio Hurtado Mosquera
  4.  * Descripcion:
  5.  * Controlar un LED RGB desde el Arduino, vía PWM con 3 potenciómetros, uno para cada color.
  6.  */
  7.  
  8. /********** Constantes **********/
  9. #define POT1    A0
  10. #define POT2    A1
  11. #define POT3    A2
  12. #define TOTLED   3 // Total LEDs
  13.  
  14.  
  15. /********** Variables **********/
  16.  
  17. int led[TOTLED] = {3, 4, 5};  
  18.  
  19. /********** Configuracion **********/
  20.  void setup() {
  21. // put your setup code here, to run once:
  22.     int pos=0;
  23.     while (pos < TOTLED){ //se realiza un while para que recorra los pines del arreglo y los configure como OUTPUT
  24.       pinMode(led[pos], OUTPUT);
  25.       pos=pos+1;
  26.     }
  27.     pinMode(POT1, INPUT);//se configuran los pines de los potenciometros como INPUT
  28.     pinMode(POT2, INPUT);
  29.     pinMode(POT3, INPUT);
  30.  } // end setup()
  31.  
  32. /********** Ciclo Principal **********/
  33.  
  34.  void loop() {
  35.  // put your main code here, to run repeatedly:
  36.   valorR = analogRead(POT1);  //se lee el valor dado por el potenciometro
  37.     valorA   = analogRead(POT2);
  38.     valorV = analogRead(POT3);
  39.    
  40.     analogWrite(3,valorR); // Cambiar la intensidad de iluminacion del LED segun el valor leido
  41.     analogWrite(4,valorA);
  42.     analogWrite(5,valorV);
  43.  
  44.  } // end loop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement