Another question from this newbie! Sorry!
I've nearly finished my turning gallery target programme now. I've managed to utilise a 2004 LCD screen and a rotary encoder to drive a menu system on the main.py script. This would open another py script to run a specific timings for the targets. At the natural end of the script, it will bounce back to the main.py script. All that is working fine.
What I'm trying to add now is a "emergency stop" switch on my timing scripts.
Here is the crucial parts of the scripts (removed the lcd.putstr stuff to reduce clutter):
Code: Select all
# Stop Button
stop = Pin(15, Pin.IN, Pin.PULL_DOWN)
# Normal Cycle
def Run():
#Cycle (0 to ntimes)
for x in range (0,1):
# 5 seconds Edge Delay
utime.sleep(5)
# Face
servoA.duty_u16(4500)
# Face time (seconds)
utime.sleep(8)
# Edge
servoA.duty_u16(1350)
# Normal End
def End():
# End in Face after (delay)
utime.sleep(3)
servoA.duty_u16(4500)
# Interrupt End
def Interrupt(Pin):
lcd.clear()
lcd.move_to(3,1)
lcd.putstr("Stopped by User")
# End in Face after (delay)
servoA.duty_u16(4500)
quit()
# Interrupt Function
stop.irq(trigger=Pin.IRQ_RISING, handler=Interrupt)
lcd.clear()
servoA.duty_u16(4500)
# 1st Line
lcd.move_to(0, 0)
lcd.putstr("MT Match 4")
lcd.putstr("Go!")
servoA.duty_u16(1350)
utime.sleep(1)
#Run Script
Run()
End()
Is there a better way of doing this?
Thanks!