Portfolio. BHSAD Arduino Prototyping | L4, Harduino: Drawing light | Page 12
RGB Led rainbow
220 ohm
5V
220 ohm
const int RED=13;
const int GREEN=11;
const int BLUE=10;
int red;
int green;
int blue;
const int POT=A0;
const int MIN_PAUSE=10;
const int MAX_PAUSE=100;
int pause;
const int VIEW_PAUSE=2000;
void setup() {
Serial.begin(9600);
}
DATA VALUES R, G, B
FOR 7 PRIMARY COLORS
OF THE RAINBOW
Color R G B
red 255 0 0
orange 255 125 0
yellow 255 255 0
green 0 255 0
light blue 0 255 255
blue 0 0 255
purple 255 0 255
void loop() {
Serial.println(“red - yellow”);
red=255; green=0; blue=0;
for(green=0; green<=255;
green++) setRGB(red, green,
blue); setpause(); delay(VIEW_
PAUSE);
setRGB(red, green, blue);
setpause();
delay(VIEW_PAUSE);
Serial.println(“green - blue”);
red=0; green=255; blue=0;
for(blue=0; blue<=255; blue++)
setRGB(red, green, blue);
setpause(); delay(VIEW_PAUSE);
setRGB(red, green, blue);
setpause();
delay(VIEW_PAUSE);
Serial.println(“blue - purple”);
red=0; green=0; blue=255;
for(red=0; red<=255; red++)
setRGB(red,green,blue);
setpause(); delay(VIEW_PAUSE);
setRGB(red,green,blue);
setpause();
delay(VIEW_PAUSE);
}
void setRGB(int r, int g, int b)
{
analogWrite(RED,r);
analogWrite(GREEN,g);
analogWrite(BLUE,b);
delay(pause);
}
void setpause()
{
pause=map(analogRead(POT), 0,
1024, MIN_PAUSE, MAX_PAUSE);
Serial.print(“pause=”);
Serial.println(pause);
}
220 ohm