led and light sensor

could someone give me an idea of how to code for a light sensor (photoresistor) to control a LED strip that uses fast.h. just peusdo code to give me an idea.

 void loop() {
 int val = analogRead(LDRPin);
 int numLedsToLight = map(val, 0, 1023, 0, NUM_LEDS);

  // First, clear the existing led values
  FastLED.clear();
  for(int led = 0; led < numLedsToLight; led++) { 
  leds[led] = CRGB::Blue; 
  }
 FastLED.show();
 }

I want the brightness of my led's to go up if it's dark and lower if it's bright

wrote out this trying to figure it out. Im brand new so not sure what's going on really just firing things in and changing hoping it will eventually work

// Variable to hold sensor value
int sensorValue;
#include <FastLED.h>

#define led_PIN 5
#define NUM_LEDS 14
#define BRIGHTNESS
#define LED_TYPE WS2811
#define COLOR_ORDER GRB
CRGB leds[NUM_LEDS];
// LED pin (PMW~)
const int ledPin = 5;

const int LedOn_StartMinLightLevel = 150;

void setup() {

pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
FastLED.addLeds<LED_TYPE, led_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );

Serial.begin(9600); // baud rate
Serial.flush();
}

void loop() {
//Read the input from A0 and store it in the variable
sensorValue = analogRead(A0);
Serial.println(sensorValue); //

int outputValue = 1023 - sensorValue;

if(outputValue < LedOn_StartMinLightLevel)
{
outputValue = 0;
}

int resultValue = map(outputValue, 0, 1023, 0, 255);

analogWrite(ledPin, resultValue);

FastLED.show();
delay(100);
}

op4732550:
I want the brightness of my led's to go up if it's dark and lower if it's bright

So:

  1. How do you change the brightness of your LEDs? I suspect there is a function in the Fast LED library to do that. Look at the documentation and/or examples for the library to see what function you call and what range of values you have to pass to that function.
  2. What values from your LDR represent 'dark' and 'bright'? You can write a little sketch to display the value you get from the analogRead() to learn those values by experiment.
  3. There is a function called 'map()' to map one range of values to another range.
    map() - Arduino Reference