juberth

Untitled

Sep 5th, 2013
1,325
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.46 KB | None | 0 0
  1.  #define MAXLED 3
  2.  
  3. int led[MAXLED] = {9,10,11};
  4. int valor = 0;
  5. int i = 0;
  6.  
  7.  
  8. void setup()
  9. {
  10.   Serial.begin(9600);
  11.   for(int i = 0; i < MAXLED ; i++)
  12.   {
  13.     pinMode(led[i], OUTPUT);
  14.   }
  15. }
  16.  
  17. void loop()
  18. {
  19.   if(Serial.available() > 0)
  20.   {
  21.     valor = Serial.read();
  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();
  29.     analogWrite(led[i], valor);
  30. }
Advertisement
Add Comment
Please, Sign In to add comment