This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

3 LED PWM2

By: a guest on Nov 25th, 2012  |  syntax: C  |  size: 0.86 KB  |  views: 60  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. byte red = 0;
  2. byte green = 0;
  3. byte blue = 0;
  4.  
  5. #define redPin 9
  6. #define bluePin 10
  7. #define greenPin 11
  8.  
  9. void setup()
  10. {
  11.   pinMode(redPin, OUTPUT);
  12.   pinMode(greenPin, OUTPUT);
  13.   pinMode(bluePin, OUTPUT);
  14. }
  15.  
  16. void loop()
  17. {
  18.    goForward();
  19.    goReverse();
  20. }
  21.  
  22. void goForward()
  23. {
  24.   for(red; red < 255; red++)
  25.   {
  26.     analogWrite(redPin, red);
  27.     delay(100);
  28.   }
  29.   for(blue; blue < 255; blue++)
  30.   {
  31.     analogWrite(bluePin, blue);
  32.     delay(100);
  33.   }
  34.   for(green; green < 255; green++)
  35.   {
  36.     analogWrite(greenPin, green);
  37.     delay(100);
  38.   }
  39.  
  40. }
  41.  
  42.  
  43. void goReverse()
  44. {
  45.   for(red; red > 0; red--)
  46.   {
  47.     analogWrite(redPin, red);
  48.     delay(100);
  49.   }
  50.   for(blue; blue > 0; blue--)
  51.   {
  52.     analogWrite(bluePin, blue);
  53.     delay(100);
  54.   }
  55.   for(green; green > 0; green--)
  56.   {
  57.     analogWrite(greenPin, green);
  58.     delay(100);
  59.   }
  60.  
  61. }
clone this paste RAW Paste Data