HI, I hate having to ask for help, but I have been trying this for two days and I can't get it to work. :~ I have made a RGB lamp with a arduino in it controlling a 3W RGB LED, it also has a Infared receiver.
I have a small remote, and have programmed it with three buttons, Off, Turns all Led's LOW. WHITE, turns on the White light, my RGB led also has a white led. And ramdom, which fades through all the colors. I found the fade code elsewhere on the internet and have tried to integrate it into my own.
MY PROBLEM
White light works, off works when on white mode, I haven't integrated turning off from the fade routine yet because I can't get fade to work. The stock fade code works great, but when I put it into my own project it ONLY randomly fades the GREEN and BLUE lights up and down, the RED doesn't come on. BUT as I said the stock code works great, and all I did was copy and paste it! I tried going through it line by line, and can't figure it out.
The fade code as pulled from the internet works as advertised
if (value1 > current_value1){
current_value1++;
analogWrite(pin1, current_value1);
delay(x);
}
if (value1 < current_value1){
current_value1--;
analogWrite(pin1, current_value1);
delay(x);
}
if (value1 == current_value1){
analogWrite(pin1, current_value1);
value1 = random(BRIGHTNESS);
}
//////////////////////////
if (value2 > current_value2){
current_value2++;
analogWrite(pin2, current_value2);
delay(x);
}
if (value2 < current_value2){
current_value2--;
analogWrite(pin2, current_value2);
delay(x);
}
if (value2 == current_value2){
analogWrite(pin2, current_value2);
value2 = random(BRIGHTNESS);
}
///////////////////////////////
if (value3 > current_value3){
current_value3++;
analogWrite(pin3, current_value3);
delay(x);
}
if (value3 < current_value3){
current_value3--;
analogWrite(pin3, current_value3);
delay(x);
}
if (value3 == current_value3){
analogWrite(pin3, current_value3);
value3 = random(BRIGHTNESS );
}
}
MY CODE PAGE ONE
pin1=red
pin2=green
pin3=blue
pin4=white
#include <IRremote.h>
int pin1 = 11;
int pin2 = 10;
int pin3 = 9;
int pin4 = 6;
int RECV_PIN = 3;
int MAX_BRIGHT = 5;
int x=10; //delay time
long value3;
long value2;
long value1;
long current_value3;
long current_value2;
long current_value1;
//----------------------------------------------------------------
#define OFF 0xFF00C03F
#define pin4_LIGHT 0xFF0040BF
#define RANDOM 0xFF00708F
#define PAUSE 0xFF00E01F
// Remote Codes
//----------------------------------------------------------------
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup()
{
irrecv.enableIRIn();
pinMode(pin1, OUTPUT);
pinMode(pin2, OUTPUT);
pinMode(pin3, OUTPUT);
pinMode(pin4, OUTPUT);
}
void loop() //--------------------------------------------------------
{
if (irrecv.decode(&results)) {
if ( results.value != 0xFFFFFFFF) {
switch (results.value) {
case OFF :
digitalWrite (pin1, LOW);
digitalWrite (pin2, LOW);
digitalWrite (pin3, LOW);
digitalWrite (pin4, LOW);
break;
case pin4_LIGHT :
analogWrite (pin4, MAX_BRIGHT);
break;
case RANDOM :
fadecode();
break;
}
}
irrecv.resume();
}
}
SECOND TAB
void fadecode(){
randomSeed(analogRead(0));
value1 = random(MAX_BRIGHT);
current_value1 = value1;
value2 = random(MAX_BRIGHT);
current_value2 = value2;
value3 = random(MAX_BRIGHT);
current_value3 = value3;
analogWrite(pin1, current_value1);
analogWrite(pin2, current_value2);
analogWrite(pin3, current_value3);
value1 = random(MAX_BRIGHT);
value2 = random(MAX_BRIGHT);
value3 = random(MAX_BRIGHT);
while(1){
if (value1 > current_value1){
current_value1++;
analogWrite(pin1, current_value1);
delay(x);
}
if (value1 < current_value1){
current_value1--;
analogWrite(pin1, current_value1);
delay(x);
}
if (value1 == current_value1){
analogWrite(pin1, current_value1);
value1 = random(MAX_BRIGHT);
}
//////////////////////////
if (value2 > current_value2){
current_value2++;
analogWrite(pin2, current_value2);
delay(x);
}
if (value2 < current_value2){
current_value2--;
analogWrite(pin2, current_value2);
delay(x);
}
if (value2 == current_value2){
analogWrite(pin2, current_value2);
value2 = random(MAX_BRIGHT);
}
///////////////////////////////
if (value3 > current_value3){
current_value3++;
analogWrite(pin3, current_value3);
delay(x);
}
if (value3 < current_value3){
current_value3--;
analogWrite(pin3, current_value3);
delay(x);
}
if (value3 == current_value3){
analogWrite(pin3, current_value3);
value3 = random(MAX_BRIGHT );
}
}
}
If anyone knows why this strange behavior is happening I would be very grateful, I just want to finish this led project. It is a quite simple project compared to my ARDUINO ultrasonic rover, and is strange that I can't figure it out, I also have built the light as a piece of furniture, so I just want it finished, this isn't something I was planning on messing with for a month.