LDR Motor control


#1

HI everyone
I am try to stop and start a motor with an ldr I have written the following code.


import time

import explorerhat

def play(channel, event):
if channel > 1:
return
if event == ‘press’:
explorerhat.motor.one.forwards(50)
if event == ‘release’:
explorerhat.motor.one.forwards(50)

explorerhat.touch.one.pressed(play)
explorerhat.touch.one.released(play)

while True:
level = explorerhat.analog.one.read()
for i in range(0, 4):
if level > float(i + 1):
explorerhat.motor.one.stop()
time.sleep(15)
if level > float(i + 1):
explorerhat.analog.one
time.sleep(20)
print(level)
time.sleep(0.25)


I would like the motor to stop for 15 sec when the light is on the ldr and then start again. The led light is in front of the ldr always and the motor moves the light blocking object in front of the ldr.