Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #define MAXLED 3 //creamos la variable maxled 3 elementos
  2.  
  3. int led[MAXLED] = {3,5,6}; //creamos un vector para los pines a utilizar
  4. int valor = 0; //creamos la variable valor 1 de tipo entero
  5. int i = 0; //creamos la variable valor 1 de tipo entero
  6.  
  7.  
  8. void setup()
  9. {
  10.   Serial.begin(9600); // la comunicacion serial sera a 9600 baudios
  11.   for(int i = 0; i < MAXLED ; i++)
  12.   {
  13.     pinMode(led[i], OUTPUT); // los pines del 3,5,6 seran de salida
  14.   }
  15. }
  16.  
  17. void loop()
  18. {
  19.   if(Serial.available() > 0) // si hay datos en el puerto serial entra a la condicion
  20.   {
  21.     valor = Serial.read(); // lee lo que hay en el puerto serial
  22.     if(valor == 'R')
  23.       i = 0;
  24.     if(valor == 'G')
  25.       i = 1;
  26.     if(valor == 'B')
  27.       i = 2;
  28.     valor = Serial.parseInt(); // lee y toma el siguiente valor convirtiandolo en entero
  29.     analogWrite(led[i], valor); // escribe el valor por el pin xx
  30.   }
  31. }