document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. /**Proyecto**
  2. *Univrsidad Santiago de Cali
  3. *Programacion en sistemas embebidos
  4. *Nicolas Roman Buitrago
  5.  
  6. *Laboratorio 5: controlar un LED RGB, con una interfaz grafica
  7. *que controla la intencidad de cada color
  8. */
  9.  
  10. int ledR = 3;
  11. int ledG = 5;
  12. int ledB = 6;
  13.  
  14. void setup() {
  15.   Serial.begin(9600);
  16.  
  17.   pinMode(ledR, OUTPUT);
  18.   pinMode(ledG, OUTPUT);
  19.   pinMode(ledB, OUTPUT);
  20.  
  21. }
  22.  
  23. void loop() {
  24.   if(Serial.available() > 0){
  25.     char color = Serial.read();
  26.     int valor = Serial.parseInt();
  27.     Serial.print(valor);
  28.    
  29.     if(color == \'R\'){
  30.       encender(ledR,valor);
  31.     }
  32.     if(color == \'G\'){
  33.       encender(ledG,valor);
  34.     }
  35.     if(color == \'B\'){
  36.       encender(ledB,valor);
  37.     }
  38.   }
  39. }
  40.  
  41. /************FUNCIONES****************/
  42. void encender (int led, int valor){
  43.   analogWrite(led,valor);
  44. }
');