//making this for a school project - first part of a bigger piece of code - stuck on this, the LED
stays on constantly and only seems to work when put the LDR in shade or sunlight then press reset.
void loop() {
lightLevel = analogRead(A0);
Serial.print("Light Level: ");
Serial.println(lightLevel, DEC);
while (lightLevel>30) {digitalWrite(led, HIGH);} //how can I get this to poll continuously rather than
while (lightLevel<30) {digitalWrite(led, LOW);} //having to press reset?
See if the variable lightLevel is above 30. It is because you haven't updated it. Yay. Go back to line 2.
Go back to the start of the loop.
You never get to line 3 because line 2 is always true. A WHILE continues to loop forever until the condition becomes false. An IF, like Runaway Pancake says tests the condition, runs once and then moves on.
You can use a while if you really want, but you need to change it to this:
while( analogRead(A0) > 30 )
{
digitalWrite(led, HIGH);
}