Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Nov 25th, 2012  |  syntax: None  |  size: 1.21 KB  |  views: 106  |  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. int red = 0;
  2. int green = 0;
  3. int blue = 0;
  4.  
  5. const int redPin = 9;
  6. const int bluePin = 10;
  7. const int greenPin = 11;
  8.  
  9. void setup()
  10. {
  11.   pinMode(redPin, OUTPUT);
  12.   pinMode(greenPin, OUTPUT);
  13.   pinMode(bluePin, OUTPUT);
  14. }
  15.  
  16.  
  17. void goForward()
  18. {
  19.   if (red < 255)
  20.   {
  21.     red++;
  22.     analogWrite(redPin, red);
  23.     delay(100);
  24.   }
  25.   else if (red = 255)
  26.   {
  27.     if (blue < 255)
  28.     {
  29.       blue++;
  30.       analogWrite(bluePin, blue);
  31.       delay(100);
  32.     }
  33.   }
  34.   else if (red == 255 & blue == 255)
  35.   {
  36.     if (green < 255)
  37.     {
  38.       green++;
  39.       analogWrite(greenPin, green);
  40.       delay(100);
  41.     }
  42.   }
  43.   else if (red == 255 || blue == 255 || green == 255)
  44.   {
  45.     goReverse;
  46.   }
  47. }
  48.  
  49.  
  50. void goReverse()
  51. {
  52. if (red > 0)
  53.   {
  54.     red--;
  55.     analogWrite(redPin, red);
  56.     delay(100);
  57.   }
  58.   else if (red == 0)
  59.   {
  60.     if (blue > 0)
  61.     {
  62.       blue--;
  63.       analogWrite(bluePin, blue);
  64.       delay(100);
  65.     }
  66.   }
  67.   else if (red == 0 || blue == 0)
  68.   {
  69.     if (green > 0)
  70.     {
  71.       green--;
  72.       analogWrite(greenPin, green);
  73.       delay(100);
  74.     }
  75.   }
  76.   else if (red == 0 || blue == 0 || green == 0)
  77.   {
  78.     goForward;
  79.   }
  80. }
  81. void loop()
  82. {
  83.    goForward();
  84.    goReverse();
  85. }