SHARE
TWEET

Color

muhsahlan May 25th, 2019 80 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     // color swirl! connect an RGB LED to the PWM pins as indicated
  2.     // in the #defines
  3.     // public domain, enjoy!
  4.      
  5.     #define REDPIN 16
  6.     #define GREENPIN 5
  7.     #define BLUEPIN 4
  8.      
  9.     #define FADESPEED 5     // make this higher to slow down
  10.      
  11.     void setup() {
  12.       pinMode(REDPIN, OUTPUT);
  13.       pinMode(GREENPIN, OUTPUT);
  14.       pinMode(BLUEPIN, OUTPUT);
  15.     }
  16.      
  17.      
  18.     void loop() {
  19.       int r, g, b;
  20.      
  21.       // fade from blue to violet
  22.       for (r = 0; r < 256; r++) {
  23.         analogWrite(REDPIN, r);
  24.         delay(FADESPEED);
  25.       }
  26.       // fade from violet to red
  27.       for (b = 255; b > 0; b--) {
  28.         analogWrite(BLUEPIN, b);
  29.         delay(FADESPEED);
  30.       }
  31.       // fade from red to yellow
  32.       for (g = 0; g < 256; g++) {
  33.         analogWrite(GREENPIN, g);
  34.         delay(FADESPEED);
  35.       }
  36.       // fade from yellow to green
  37.       for (r = 255; r > 0; r--) {
  38.         analogWrite(REDPIN, r);
  39.         delay(FADESPEED);
  40.       }
  41.       // fade from green to teal
  42.       for (b = 0; b < 256; b++) {
  43.         analogWrite(BLUEPIN, b);
  44.         delay(FADESPEED);
  45.       }
  46.       // fade from teal to blue
  47.       for (g = 255; g > 0; g--) {
  48.         analogWrite(GREENPIN, g);
  49.         delay(FADESPEED);
  50.       }
  51.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top