Hi all, I am doing my first real arduino project with my niece, making a RGB color mixing box/projector for her school science fair project. I am using a duemilanove 168 to drive a 10w smd rgb led using resistors and three TIP122 transistors. Three pots (with rgb painted knobs of course) provide the analog input. I am desperately trying to learn to code, its one of the few things I haven't been able to learn on my own on the net, it's a little daunting at times. My problem is this led is way too bright and gets too hot, I don't want it blinding children while melting down in the classroom. The other problem is I accidently burned out one of the three red led's in the module(9 total) by using too little resistance while testing so red is a little dimmer. I don't have the time or extra money right now to rebuild so what I want to do is limit the max duty cycle of the pwm of each led output until I find a not so bright cool running temp and all are even. But I also want the pots to smoothly vary the output from 0%-max(limited) pwm. I tried to play with the code a little but got some wonky results, I just don't have enough practice to get a good enough understanding on how to modify it although I clearly grasp the concepts. I have many more arduino projects planed so does anyone have a good site or book they recommend to a programming noob? Thanks in advance for any help, here is the code I'm using:
// Init the Pins used for PWM
const int redPin = 9;
const int greenPin = 10;
const int bluePin = 11;
// Init the Pins used for 10K pots
const int redPotPin = 0;
const int greenPotPin = 1;
const int bluePotPin = 2;
// Init our Vars
int currentColorValueRed;
int currentColorValueGreen;
int currentColorValueBlue;
void setup()
{
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
}
void loop()
{
// Read the voltage on each analog pin then scale down to 0-255 and inverting the value for common anode
currentColorValueRed = (255 - map( analogRead(redPotPin), 0, 1024, 0, 255 ) );
currentColorValueBlue = (255 - map( analogRead(bluePotPin), 0, 1024, 0, 255 ) );
currentColorValueGreen = (255 - map( analogRead(greenPotPin), 0, 1024, 0, 255 ) );
// Write the color to each pin using PWM and the value gathered above
analogWrite(redPin, currentColorValueRed);
analogWrite(bluePin, currentColorValueBlue);
analogWrite(greenPin, currentColorValueGreen);
}