Advertisement
3rdWard_Arduino

class2_PWM_conrol_RGB_LED

Mar 18th, 2012
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.52 KB | None | 0 0
  1. /*
  2. control RGB Led with PWM
  3. matt R, 3/18/2012
  4. */
  5.  
  6. int rPin = 3, gPin = 5, bPin = 6;// red,green,blue led pins
  7. int rPWM = 0, gPWM = 85, bPWM = 170;// PWM values for the leds
  8.  
  9. void setup(){
  10.  Serial.begin(9600);
  11. }
  12.  
  13. void loop(){
  14.  
  15.   rPWM = rPWM + 1;
  16.   if(rPWM >= 255){
  17.    rPWM = 0;
  18.   }
  19.   analogWrite( rPin, rPWM);
  20.  
  21.   gPWM = gPWM + 1;
  22.   if(gPWM >= 255){
  23.    gPWM = 0;
  24.   }
  25.   analogWrite( gPin, gPWM);
  26.  
  27.   bPWM = bPWM + 1;
  28.   if(bPWM >= 255){
  29.    bPWM = 0;
  30.   }
  31.   analogWrite( bPin, bPWM);
  32.  
  33.   delay(50);
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement