Help with colour changing night light programme

hi every1

Im looking some help with a project im working on , the purpose is to have a night light with 3 colours (RGB LED) which glows brighter as the room get darker . The colour of the light is controlled by pressing a button which changes the colour form red to green to blue to off .

The problem im having is this, I cant get the light mode to change between red green and blue when the photo resistor is covered the colours are changing therw the whole spectrom (all portions of my rgb led seem to be on at all times)when i press the button it doens nothing atall ! ive tried to use 2 different code form my text book when writing this programme , a photo sensor one and a rgb led mode select one both of these work perfectly when running on their own.

here is my code im an absolute beginner to this so any help woul dbe greatly apreciated

const int RLED=9; //blue led on pin 9 green led pin 10 red led pin 11

const int BLED=10;

const int GLED=11;

const int BUTTON=2; // button on pin 2

boolean lastButton = LOW; //last button status

boolean currentButton = LOW; // current button status

int ledMode = 0; // cycle between led modes

const int LIGHT=0; // set light sensor on pin A0

const int MIN_LIGHT=904; // min light reading

const int MAX_LIGHT=1011; // max light reading

int val = 0; //variable to hold analogue reading form light sensor

int LED = 0; // variable to hold the calue for led brightness

void setup () { pinMode (BLED, OUTPUT); // set blue led as an output pinMode (GLED, OUTPUT); // set green led as an ouutput pinMode (RLED, OUTPUT); // set red led as an output }

boolean debounce(boolean last) { boolean current = digitalRead(BUTTON); //read the button state

if (last != current) //if its different { delay(5); // wait 5 ms } current = digitalRead(BUTTON); // read it again

return current; }

//led mode set pass a number for the led mode and set it accordingly

void setMode(int mode) { //red if (mode == 1) { analogWrite(RLED, LED); digitalWrite(GLED, LOW); digitalWrite(BLED, LOW); }

//GREEN else if (mode == 2) { digitalWrite(RLED, LOW); analogWrite(GLED, LED); digitalWrite(BLED, LOW); }

//BLUE else if (mode == 3) { digitalWrite(RLED, LOW); digitalWrite(GLED, LOW); analogWrite(BLED, LED); } else if (mode == 0) { digitalWrite(RLED, LOW); digitalWrite(GLED, LOW); digitalWrite(BLED, LOW); } }

void loop () { currentButton = debounce(lastButton);

if (lastButton == LOW && currentButton == HIGH) { ledMode++; }

lastButton = currentButton;

if (ledMode == 4) ledMode = 0; setMode(ledMode);

val = analogRead(LIGHT); //reading value from light sensor val = map(val, MIN_LIGHT, MAX_LIGHT, 255, 0); //record light reading val = constrain(val, 0, 255); //keep value between 0 - 255 analogWrite(val, LED);

}

here is my code im an absolute beginner to this so any help woul dbe greatly apreciated

Can I suggest that the first thing you do is to read and follow the advice in http://forum.arduino.cc/index.php?topic=97455.0 regarding how to post code.

  analogWrite(val, LED);

Right there?

Please use code tags.

the tag for this should be // transfer val to LED brightness

i have tryed this portion of code as analogWrite(val, LED); and analogWrite(LED, val); sorry any inconvinience for posting my code like this ill read and follwo the rules properly in future

the tag for this should be // transfer val to LED brightness

? Read your code again, paying particular attention to the possible range of "val", and ask yourself "Do I have that many pins?"