For the Actuator experiment, we worked with the RGB LED light. We wanted to play around with timing and switching colors. The tutorial we followed showed us how to program the LED to change colors on a specific schedule. The tutorial can be found here: https://learn.adafruit.com/adafruit-arduino-lesson-3-rgb-leds/other-things-to-do
The LED had 4 Arduino connections, 1 to ground and the 3 others to pins, each correlated to red, green, and blue. Here is the board/Arduino layout:
We started by experimenting with pure red, green and blue lights. We wanted to change the colors, so we looked online and found values we liked. We used (255, 0, 0) for red, (255, 165, 0) for orange, (255, 255, 0) for yellow, (0, 128, 0) for green, and (0, 255, 255) for teal blue.
Arduino Code:
int redPin = 11;
int greenPin = 10;
int bluePin = 9;
//uncomment this line if using a Common Anode LED
//#define COMMON_ANODE
void setup()
{
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
}
void loop()
{
setColor(255, 0, 0); // red
delay(1000);
setColor(255, 165, 0); // orange
delay(1000);
setColor(255, 255, 0); // yellow
delay(1000);
setColor(0, 128, 0); //green
delay(1000);
setColor(0, 255, 255); //blue
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);
}
No comments:
Post a Comment