Skip to content

Instantly share code, notes, and snippets.

@puterleat
Last active August 29, 2015 14:09
Show Gist options
  • Select an option

  • Save puterleat/956c10af871395b672e1 to your computer and use it in GitHub Desktop.

Select an option

Save puterleat/956c10af871395b672e1 to your computer and use it in GitHub Desktop.
def _at_top_generator(self):
"""Introduce 5ms delay in readings and hysteresis for change in state"""
pin = live_pins[self.name]['limit_top_pin']
windowlen = 10
window = deque(maxlen=windowlen)
window.extend([True]*windowlen)
state = True
while True:
gevent.sleep(.0005) # 5ms
window.append(pin.read())
if all(window):
state = True
elif not any(window):
state = False
yield state
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment