Hardware Reference
In-Depth Information Writing Program
Now we implement our RGB LED controller in Arduino. This is for testing. Open Firstly,
we define our RGB LED pins. The following is RGB LED pins for Arduino Yún.
int redPin = 11 ;
int greenPin = 10 ;
int bluePin = 9 ;
Now we initialize pins on setup().
void setup ()
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
Serial.begin( 9600 );
We define a function, called setColor(). This function aims to write RGB values on PWM
pins. We can use analogWrite(), http://arduino.cc/en/Reference/AnalogWrite .
void setColor ( int red, int green, int blue)
analogWrite(redPin, red);
analogWrite(greenPin, green);
analogWrite(bluePin, blue);
Now we control RGB values on RGB LED, for instance, Red, Green, Blue, Yellow, Purple,
void loop ()
setColor( 255 , 0 , 0 ); // red
Search WWH ::

Custom Search