// Quick and basic sketch to demo the Power LED Shield // It assumes you have a Red, Green, Blue and White LED - one color each channel // But any combination of colors can be used on any channel // LED PWM output pins #define RedPin 3 #define GrnPin 9 #define BluPin 10 #define WhtPin 11 // Analog input pins for controlling the LEDs with potentiometers. #define RedAdj 0 #define GrnAdj 1 #define BluAdj 2 #define WhtAdj 3 // Uncomment this line to enable serial output of the LED values //#define DEBUG int Red; // The state of the Red LED int Grn; // The state of the Green LED int Blu; // The state of the Blue LED int Wht; // The state of the White LED void setup() { // Uncomment one or both of the following lines to change the PWM frequency. // See - http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1235060559/4#4 for more information. // The default is about 488Hz. // TCCR1B = TCCR1B & 0b11111000 | 0x02; // Sets the PWM freq to about 3900 Hz on pins 3 and 11 // TCCR2B = TCCR2B & 0b11111000 | 0x02; // Sets the PWM freq to about 3900 Hz on pins 9 and 10 // Enable the serial console if DEBUG is defined above #ifdef DEBUG Serial.begin(9600); #endif // Sets the LED control pins to outputs pinMode(RedPin, OUTPUT); pinMode(GrnPin, OUTPUT); pinMode(BluPin, OUTPUT); pinMode(WhtPin, OUTPUT); } // This is a function that sets the LED brightness values when called below void WriteLEDArray() { analogWrite(RedPin, Red); analogWrite(GrnPin, Grn); analogWrite(BluPin, Blu); analogWrite(WhtPin, Wht); } void loop() { // Produces random brightness values // Red = random(255); // Grn = random(255); // Blu = random(255); // Wht = random(255); // or // Full brightness on all LEDs // Good for checking white balance and adjusting manual brightness // Red = 255; // Grn = 255; // Blu = 255; // Wht = 255; // or // Controls the LEDs from input at the analog pins // The analog inputs range from 0-1023, but the PWM outputs range from 0-255. // So we use the map() function to scale the values. // Need a potentiometer on each of the 4 analog pins Red = map(analogRead(RedAdj),0,1023,0,255); Grn = map(analogRead(GrnAdj),0,1023,0,255); Blu = map(analogRead(BluAdj),0,1023,0,255); Wht = map(analogRead(WhtAdj),0,1023,0,255); // Call the function to set the LED values WriteLEDArray(); // Write the LED values to the serial console if DEBUG is defined above #ifdef DEBUG Serial.print(Red); Serial.print("\t"); Serial.print(Grn); Serial.print("\t"); Serial.print(Blu); Serial.print("\t"); Serial.println(Wht); #endif // Wait a second before doing it all again delay(1000); }