I would like to run a function that turns on and off a LED when the light level is under 100.
I gave it a try, but it did not work. Can anyone help?
Here´s the code:
lightlevel = 0
def turn_off():
pins.digital_write_pin(DigitalPin.P1, 0)
def intervall():
pins.digital_write_pin(DigitalPin.P1, 1)
basic.pause(1000)
pins.digital_write_pin(DigitalPin.P1, 0)
basic.pause(randint(1000, 5000))
def on_forever():
global lightlevel
lightlevel = input.light_level()
if input.light_level() >= 100:
intervall()
else:
turn_off()
basic.forever(on_forever)