I've been fiddling around some more with Arduino. Using some of their tutorials for ideas, I programmed an RGB LED to flash rainbow colors! An RGB LED is like a freak of nature. It's like an LED, but with FOUR legs instead of two and you can adjust the RGB values that go into each leg to make it a certain color.
Here's the code if anyone's interested:
// sets pins for the LEDs:
const int redPin = 3;
const int greenPin = 5;
const int bluePin = 6;
const int power = 9;
void setup() {
// initialize serial:
Serial.begin(9600);
// make the pins outputs:
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
pinMode(power,OUTPUT); }
void loop() {
int red = 255;
int green = 0;
int blue = 0;
for(int red = 255; red >127; red--)
{
green = green++;
analogWrite(power, HIGH);
analogWrite(redPin, red);
analogWrite(greenPin,green);
delay(5);
}
for(int red = 127; red >0; red--)
{green = green++;
analogWrite(power, HIGH);
analogWrite(redPin, red);
analogWrite(greenPin,green);
delay(5);}
for(int green= 255; green >127; green--)
{blue = blue++;
analogWrite(power, HIGH);
analogWrite(bluePin, blue);
analogWrite(greenPin,green);
delay(5);}
for(int green = 127; green >0; green--)
{blue = blue++;
analogWrite(power, HIGH);
analogWrite(bluePin, blue);
analogWrite(greenPin,green);
delay(5);}
for(int blue= 255; blue >127; blue--)
{ red =red++;
analogWrite(power, HIGH);
analogWrite(bluePin, blue);
analogWrite(redPin,red);
delay(5);}
for(int blue = 127; blue >0; blue--)
{ red =red++;
analogWrite(power, HIGH);
analogWrite(bluePin, blue);
analogWrite(redPin,red);
delay(5);}
}
No comments:
Post a Comment