Hi again,
First of all, I'm a beginner when it comes to coding....
I have looked at your suggestions and I don't fully understand what going on.
Anyway I have spend the last days going through tutorials on youtube and I have cooked something
together, code is below...please don't laugh:)
The end part of the code, I have alot of serial.print commands. I use these to better see whats going on in the program.
Now a short explanation: The code takes a light mesurement, and call this "value1" Then we wait for a second and takes another measurement and call this "value2"
Then the code figures out what of the 2 values are the lowest, by using if commands.
My problem now is to use the lowest value in the rest of the program where I adjust the led's brightness according to the lowest value. how do I make a variable called "value"?
as you can see I tried to do it this way:
if (value1<value2)
{
int value=value1;
and so on....
whole loop here:
void loop() {
uint16_t Light_Intensity = LightSensor.GetLightIntensity();// Get Lux value
Serial.print("Light: ");
Serial.print(Light_Intensity);
Serial.println(" lux");
Serial.println();
// call GetLightIntensity() Function , so the sensor read
//the Intensity Value and send it
Light_Intensity=LightSensor.GetLightIntensity();
int value1=Light_Intensity;
delay(2000); // wait for 2 seconds
// call GetLightIntensity() Function , so the sensor read
//the Intensity Value and send it
Light_Intensity=LightSensor.GetLightIntensity();
int value2=Light_Intensity;
//Determine what mesurement is lowest of 2
if (value1<value2)
{
int value=value1;
}
else if (value1>value2)
{
int value=value2;
}
else if (value1==value2)
{
int value=value1;
}
Serial.println(value1);
//Adjust LED bightnest according to Lux value
if (value>=0 && value<=4)
{
analogWrite(LedPin,38);
Serial.println("1");
}
else if (value>4 && value<=40)
{
analogWrite(LedPin,64);
Serial.println("2");
}
else if(value>40 && value<=400)
{
analogWrite(LedPin,120);
Serial.println("3");
}
else if (value>400 && value<=4000)
{
analogWrite(LedPin,220);
Serial.println("4");
}
else if (value>4000)
{
analogWrite(LedPin,255);
Serial.println("5");
}
}
By the way, next step for me is probaly to use a timer instead of delays... but small steps:)