I am trying to use the Automation HAT as a pulse generator and the timing seems to be quite erratic when I attach a scope. The code below should generate pulses every 1s and displaying the time in the debug window seems to confirm the timing but when I measure the pulses with a storage scope the timing is up to half a second out.
Sorry about the indentation. It gets stripped out when I hit post.
My code is
#!/usr/bin/env python
import time
import math
import automationhat
if automationhat.is_automation_hat():
automationhat.light.power.write(1)
lTriggers = 0
starttime = time.clock()
trigger_on = 0
while True:
time_ms = 1000.0 * (time.clock() - math.floor(time.clock()))
if trigger_on == 0:
if time_ms > 900:
trigger_on = 1
automationhat.output.one.on()
if trigger_on == 1:
if time_ms < 50:
trigger_on = 0
automationhat.output.one.off()
lTriggers = lTriggers + 1
if lTriggers >= 100:
break