TSL2591 turn on LED, how do I write the if statement

how do i write the code so i can light up a led when it gets dark?
code:
// TSL2591_I2C.ino
//
// shows how to use the TSL2591MI library with the sensor connected using I2C.
//
// Copyright (c) 2019-2020 Gregor Christandl
//
// connect the TSL2591 to the Arduino like this:
//
// Arduino - TSL2591
// 3.3V ---- VCC
// GND ----- GND
// SDA ----- SDA
// SCL ----- SCL
// other pins can be left unconnected.

#include <Arduino.h>
#include <Wire.h>
#include <TSL2591I2C.h>

int ledPin=13;

TSL2591I2C tsl2591;

void setup() {
// put your setup code here, to run once:
Serial.begin(9600);

pinMode(ledPin,OUTPUT);

//wait for serial connection to open (only necessary on some boards)
while (!Serial);

#if defined(ESP32)
Wire.begin(SDA, SCL);
#elif defined(ESP8266)
Wire.begin(D2, D3);
#else
Wire.begin();
#endif

if (!tsl2591.begin())
{
	Serial.println("begin() failed. check the connection to your TSL2591.");
	while (1);
}

Serial.print("sensor ID: "); Serial.println(tsl2591.getID(), HEX);

tsl2591.resetToDefaults();

//set channel
tsl2591.setChannel(TSL2591MI::TSL2591_CHANNEL_0);

//set gain
tsl2591.setGain(TSL2591MI::TSL2591_GAIN_MED);

//set integration time
tsl2591.setIntegrationTime(TSL2591MI::TSL2591_INTEGRATION_TIME_100ms);

}

void loop() {
// put your main code here, to run repeatedly:

delay(1000);

//start a measurement
if (!tsl2591.measure())
{
	Serial.println("could not start measurement. ");
	return;
}

//wait for the measurement to finish
do
{
	delay(100);
} while (!tsl2591.hasValue());

Serial.print("Irradiance: "); Serial.print(tsl2591.getIrradiance(), 7); Serial.println(" W / m^2");
Serial.print("Brightness: "); Serial.print(tsl2591.getBrightness(), 7); Serial.println(" lux");

}

I moved your topic to an appropriate forum category @ulfer.

In the future, please take some time to pick the forum category that best suits the subject of your topic. There is an "About the _____ category" topic at the top of each category that explains its purpose.

This is an important part of responsible forum usage, as explained in the "How to get the best out of this forum" guide. The guide contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

I guess is will be something like:

if( tsl2591.getBrightness() < 1234 ) {   // enter your threshold in LUX
   digitalWrite( ledPin, HIGH ) ;
}
else {
   digitalWrite( ledPin, LOW) ;
}

Edit

If you get compiler errors in your original code or the suggested solution doesn't work then post a link to the tutorial your are following.
The similarly named adafruit library Adafruit_TSL2591 does not appear to have a getBrightness() method.

I have entered your recommended IF code but I get the following message:
C:\Users\ulfer\Downloads\FIYHYPSJJT6PZ2V\FIYHYPSJJT6PZ2V.ino: In function 'void loop()':
C:\Users\ulfer\Downloads\FIYHYPSJJT6PZ2V\FIYHYPSJJT6PZ2V.ino:162:7: error: 'tsl2591' was not declared in this scope
if( tsl2591.getBrightness() < 1234 ) { // enter your threshold in LUX
^~~~~~~
C:\Users\ulfer\Downloads\FIYHYPSJJT6PZ2V\FIYHYPSJJT6PZ2V.ino:163:18: error: 'ledPin' was not declared in this scope
digitalWrite( ledPin, HIGH ) ;
^~~~~~
C:\Users\ulfer\Downloads\FIYHYPSJJT6PZ2V\FIYHYPSJJT6PZ2V.ino:163:18: note: suggested alternative: 'lldiv'
digitalWrite( ledPin, HIGH ) ;
^~~~~~
lldiv
C:\Users\ulfer\Downloads\FIYHYPSJJT6PZ2V\FIYHYPSJJT6PZ2V.ino:166:18: error: 'ledPin' was not declared in this scope
digitalWrite( ledPin, LOW) ;
^~~~~~
C:\Users\ulfer\Downloads\FIYHYPSJJT6PZ2V\FIYHYPSJJT6PZ2V.ino:166:18: note: suggested alternative: 'lldiv'
digitalWrite( ledPin, LOW) ;
^~~~~~
lldiv

exit status 1

Compilation error: 'tsl2591' was not declared in this scope

Please post:
(a) The complete code (please use code tags).
(b) A link to the tutorial you are following.

The code snippet I posted should have been placed just before the last '}' in the loop().

/* TSL2591 Digital Light Sensor /
/
Dynamic Range: 600M:1 /
/
Maximum Lux: 88K */

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include "Adafruit_TSL2591.h"
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);

// Example for demonstrating the TSL2591 library - public domain!

// connect SCL to I2C Clock
// connect SDA to I2C Data
// connect Vin to 3.3-5V DC
// connect GROUND to common ground

Adafruit_TSL2591 tsl = Adafruit_TSL2591(2591); // pass in a number for the sensor identifier (for your use later)
#define SSD1306_LCDHEIGHT 64
//
/*
Displays some basic information on this sensor from the unified
sensor API sensor_t type (see Adafruit_Sensor for more information)
*/
/
/

//
/*
Configures the gain and integration time for the TSL2591
*/
/
/
void configureSensor(void)
{
// You can change the gain on the fly, to adapt to brighter/dimmer light situations
//tsl.setGain(TSL2591_GAIN_LOW); // 1x gain (bright light)
tsl.setGain(TSL2591_GAIN_MED); // 25x gain
//tsl.setGain(TSL2591_GAIN_HIGH); // 428x gain

// Changing the integration time gives you a longer time over which to sense light
// longer timelines are slower, but are good in very low light situtations!
//tsl.setTiming(TSL2591_INTEGRATIONTIME_100MS); // shortest integration time (bright light)
// tsl.setTiming(TSL2591_INTEGRATIONTIME_200MS);
tsl.setTiming(TSL2591_INTEGRATIONTIME_300MS);
// tsl.setTiming(TSL2591_INTEGRATIONTIME_400MS);
// tsl.setTiming(TSL2591_INTEGRATIONTIME_500MS);
// tsl.setTiming(TSL2591_INTEGRATIONTIME_600MS); // longest integration time (dim light)

/* Display the gain and integration time for reference sake */
Serial.println(F("------------------------------------"));
Serial.print (F("Gain: "));
tsl2591Gain_t gain = tsl.getGain();
switch(gain)
{
case TSL2591_GAIN_LOW:
Serial.println(F("1x (Low)"));
break;
case TSL2591_GAIN_MED:
Serial.println(F("25x (Medium)"));
break;
case TSL2591_GAIN_HIGH:
Serial.println(F("428x (High)"));
break;
case TSL2591_GAIN_MAX:
Serial.println(F("9876x (Max)"));
break;
}
Serial.print (F("Timing: "));
Serial.print((tsl.getTiming() + 1) * 100, DEC);
Serial.println(F(" ms"));
Serial.println(F("------------------------------------"));
Serial.println(F(""));
}

//
/*
Program entry point for the Arduino sketch
*/
/
/
void setup(void)
{
Serial.begin(9600);

Serial.println(F("Starting Adafruit TSL2591 Test!"));

if (tsl.begin())
{
Serial.println(F("Found a TSL2591 sensor"));
}
else
{
Serial.println(F("No sensor found ... check your wiring?"));
while (1);
}

/* Configure the sensor */
configureSensor();

// Now we're ready to get readings ... move on to loop()!

// by default, we'll generate the high voltage from the 3.3v line internally! (neat!)

display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3C (for the 128x64)
// init done

// Show image buffer on the display hardware.
// Since the buffer is intialized with an Adafruit splashscreen
// internally, this will display the splashscreen.
// display.display();

// Clear the buffer.
display.clearDisplay();
}

//
/*
Show how to read IR and Full Spectrum at once and convert to lux
*/
/
/
void advancedRead(void)
{
// More advanced data read example. Read 32 bits with top 16 bits IR, bottom 16 bits full spectrum
// That way you can do whatever math and comparisons you want!
uint32_t lum = tsl.getFullLuminosity();
uint16_t ir, full, vis;
float ndvi;
ir = lum >> 16;
full = lum & 0xFFFF;
vis = (full - ir);
ndvi = (1.*ir-1.*vis)/(1.*ir+1.*vis);

// Clear the buffer.
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(0,0);
display.print("All: "); display.println(full);
display.setTextColor(BLACK,WHITE);
display.print("Vis: "); display.println(vis);
display.print("Nir: "); display.println(ir);
display.print("NDVI:"); display.println(ndvi);
display.display();

Serial.print(full); Serial.print(F(" ")); Serial.print(vis); Serial.print(F(" ")); Serial.print(ir); Serial.print(F(" ")); Serial.println(ndvi);
}

//
/*
Arduino loop function, called once 'setup' is complete (your own code
should go here)
*/
/
/
void loop(void)
{
if( tsl2591.getBrightness() < 1234 ) { // enter your threshold in LUX
digitalWrite( ledPin, HIGH ) ;
}
else {
digitalWrite( ledPin, LOW) ;
}
advancedRead();
delay(500);
}

What you have just posted is completely different to your original post.
You should always post code using code tags otherwise it is difficult to read.
Start by reading the guide already mentioned in post #2 in this thread.

@ulfer start with the code you want to post in a project window in the IDE, like all the sketches you've worked with.

Use the IDE Autoformat tool to make it pretty, or prettier anyway.

Then use the IDE Copy for Forum tool.

Lastly, come here and in a new posting on this thread, paste what you copied from the IDE.

So your code looks like code, viz:

void setup() {

}

void loop() {

}

TIA and HTH

a7

Thank you very much. It works now.

I guess then this code cracked it . . .

Thanks for reporting back. Success stories are always good to hear.