Basic code to create an LED of any colour from an RGB LED.
Please let me know if you experience any problems with this code. Be sure to check back for more Arduino code.
Schematic:
Code:
/*
Oliver Holden
Created 28/10/2014
Components:
* Arduino UNO
* RGB LED
* 3x 220 ohm resistors
- Create an LED that can dispaly any colour you want
Schematic for this project is on
http://breadboarder.blogspot.co.uk/
*/
int redPin = 11; // Red LED, connected to digital pin 11
int grnPin = 10; // Green LED, connected to digital pin 10
int bluPin = 9; // Blue LED, connected to digital pin 9
void setup()
{
pinMode(redPin, OUTPUT); // Setting LED pins as outputs
pinMode(grnPin, OUTPUT);
pinMode(bluPin, OUTPUT);
}
void loop()
{
setColor(255, 255, 255); // (R,G,B) - change the numbers to a value between 0 and 255
}
void setColor(int red, int green, int blue) // Setting colours
{
analogWrite(redPin, red);
analogWrite(grnPin, green);
analogWrite(bluPin, blue);
}
No comments:
Post a Comment