Interfacing RGB LED with Arduino
Working Video:
Example Code:
// RGB LED (Common Anode)
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2); //LCD address 0x27
int redPin= 5;
int greenPin = 6;
int bluePin = 7;
void setup() {
lcd.init(); // initialize the lcd
lcd.backlight(); // lcd backlight ON
lcd.setCursor(0,0); // 0 row, 0 column
//Defining the pins as OUTPUT
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
}
void loop() {
setColor(0, 255, 255); // Red Color
delay(2000);
setColor(255, 0, 255); // Green Color
delay(2000);
setColor(255, 255, 0); // Blue Color
delay(2000);
setColor(0, 0, 0); // White Color
delay(2000);
}
void setColor(int redValue, int greenValue, int blueValue) {
analogWrite(redPin, redValue);
analogWrite(greenPin, greenValue);
analogWrite(bluePin, blueValue);
lcd.clear();
lcd.print("Red=");
lcd.print(255-redValue);
lcd.print(" ");
lcd.print("Grn=");
lcd.print(255-greenValue);
lcd.setCursor(0,1);
lcd.print("Blue=");
lcd.print(255-blueValue);
}
No comments:
Post a Comment