public
Last active

A quick script that makes my raspi light up for different ping times. It's a terrible hack, and was not written with the intent of making it public. Please don't hurt me.

  • Download Gist
gistfile1.py
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
#!/usr/bin/env python
 
import RPi.GPIO as gpio
from time import sleep
import re
import sys
 
gpio.setmode(gpio.BCM)
red = 23
yel = 24
grn = 25
lit = 22
on = red
blink = .05
 
def fastflash(pin):
for i in range(3):
gpio.output(pin, gpio.HIGH)
sleep(blink)
gpio.output(pin, gpio.LOW)
sleep(blink)
 
def setup(lights):
for pin in lights:
gpio.setup(pin, gpio.OUT)
gpio.output(pin, gpio.LOW)
 
def main():
global on
setup([red, yel, grn, lit])
while True:
line = sys.stdin.readline()
gpio.output(lit, gpio.HIGH)
sleep(blink)
gpio.output(lit, gpio.LOW)
match = re.match(r'.*? time ?= ?(\d+)(?:\.\d+)? ?ms.*', line)
 
if not match or len(match.group(1)) < 1:
gpio.output(on, gpio.LOW)
fastflash(red)
on = red
elif len(match.group(1)) <= 2:
gpio.output(on, gpio.LOW)
gpio.output(grn, gpio.HIGH)
on = grn
elif len(match.group(1)) == 3:
gpio.output(on, gpio.LOW)
gpio.output(yel, gpio.HIGH)
on = yel
else:
gpio.output(on, gpio.LOW)
gpio.output(red, gpio.HIGH)
on = red
 
if __name__ == '__main__':
try:
main()
finally:
gpio.cleanup()

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.