Very easy question about LED control via LDR

Hi there,

I am new to Arduino and have one of those problems where you know there is a simple solution but a few attempts have not worked..!

I have a code which works perfectly for controlling the brightness of 3 LEDs from one LDR, and all I want to do is the opposite, so that when the LDR is covered, the LEDs get darker instead of brighter.

Have tried a couple of things but nothing is working properly, so thought I would ask for some help, if anyone could point me in the right direction I would be very grateful!

Thank you in advance,

Here is my code:

//analog in - values from light sensor

//variables
#define ledpinA 10 //PWM pin
#define ledpinB 11
#define ledpinC 9
#define sensor 1
int val=0;
int bright=0;


//SETUP
void setup()
{
  pinMode(ledpinA,OUTPUT);
  pinMode(ledpinB,OUTPUT);
  pinMode(ledpinC,OUTPUT);
  Serial.begin(9600);
}

//LOOP
void loop()
{
  val=analogRead(sensor);
  Serial.println(val);
  //values up to 917
  val=constrain(val,0,917);
  bright=map(val,0,917,0,255);
  analogWrite(ledpinA,bright);
  analogWrite(ledpinB,bright);
  analogWrite(ledpinC,bright);
  delay(100);
}

but nothing is working properly

. . . .for some definitions of "properly"

What is it doing?

I think you can just reverse the 0 and 255 in your map:

//bright=map(val,0,917,0,255);
bright=map(val,0,917,255,0);

JimboZA: I think you can just reverse the 0 and 25

JimboZA: I think you can just reverse the 0 and 255 in your map:

Or simply reverse the LED connections.