Hackster is hosting Impact Spotlights: AI. Watch the stream live on Thursday!Hackster is hosting Impact Spotlights: AI. Stream on Thursday!
Nadeem Ahmed
Published © MIT

RGB LED

"Red-Green-Blue Light-Emitting Diode") Bit is a special light whose color you can adjust.

BeginnerFull instructions provided1 hour1,213
RGB LED

Things used in this project

Hardware components

ATtiny85
Microchip ATtiny85
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Roland Modela MDX-20

Story

Read more

Schematics

rgb

schematic and trace

Code

RGB code

Arduino
int redPin = 1;
int greenPin = 2;
int bluePin = 0;
#define COMMON_ANODE

void setup()
{
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT); 
}

void loop()
{
setColor(255, 0, 0);
delay(1000);
setColor(0, 255, 0);
delay(1000);
setColor(0, 0, 255);
delay(1000);
setColor(255, 255, 0);
delay(1000); 
setColor(80, 0, 80);
delay(1000);
setColor(0, 255, 255);
delay(1000);
}

void setColor(int red, int green, int blue)
{
#ifdef COMMON_ANODE
red = 255 - red;
green = 255 - green;
blue = 255 - blue;
#endif 
analogWrite(redPin, red);
analogWrite(greenPin, green);
analogWrite(bluePin, blue); 
}

Credits

Nadeem Ahmed
6 projects • 14 followers
I love making new things
Contact

Comments

Please log in or sign up to comment.