Chapter 19 – Experiment 11 – DISCO PARTY

Do you want to make a disco party at home but you cannot make the right atmosphere? Arduino can help you with this simple experiment!

LEDs are great. But with any project there comes a point where flashing is simply not enough. For these cases an RGB (Red, Green and Blue) LED is the right answer. With an RGB LED you’ll be able to produce any colour glow you desire.

At first using an RGB LED seems quite complex, but it quite quickly becomes clear that its no more difficult than controlling one of their single colour LED.

An RGB LED is simply a three LEDs crammed into a single LED package using four wires. There is one led for each red, green, and blue element. These three colors share the same (anode or catode, it depends on the type of led) terminal, which means that this RGB LED has a “common anode” connection. With the control of the intensity using the Pulse Width Modulation (PWM) you can create all the colors of the rainbow.

Ok, so now is time to party!

The breadboard should look like this:

11 - DISCO - RGB

 

The schema:

11 - DISCO PARTY - RGB

 

 

The Code for doing this:

int redPin = 12;
int greenPin = 11;
int bluePin = 10;
void setup()
{
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
}
void loop()
{
setColor(255, 0, 0); // red
delay(1000);
setColor(0, 255, 0); // green
delay(1000);
setColor(0, 0, 255); // blue
delay(1000);
setColor(255, 255, 0); // yellow
delay(1000);
setColor(80, 0, 80); // purple
delay(1000);
setColor(0, 255, 255); // aqua
delay(1000);
setColor(255, 255, 255);
delay(1000);
}
void setColor(int red, int green, int blue)
{
for(int fadeValue = 0 ; fadeValue <= red; fadeValue +=5)
{ // sets the value (range from 0 to 255):
analogWrite(redPin, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(30);
}
for(int fadeValue = 0 ; fadeValue <= green; fadeValue +=5)
{ // sets the value (range from 0 to 255):
analogWrite(greenPin, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(30);
}
for(int fadeValue = 0 ; fadeValue <= blue; fadeValue +=5)
{ // sets the value (range from 0 to 255):
analogWrite(bluePin, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(30);
}
}

 

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>


istanbul evden eve nakliyat istanbul evden eve nakliyat istanbul evden eve nakliyat sarıyer evden eve nakliyat beylikdüzü evden eve nakliyat şişli evden eve nakliyat