Skip to content

Instantly share code, notes, and snippets.

@flyte
Created August 14, 2014 14:16
Show Gist options
  • Save flyte/12ec2aa2c6c74b1c8d1b to your computer and use it in GitHub Desktop.
Save flyte/12ec2aa2c6c74b1c8d1b to your computer and use it in GitHub Desktop.
Publish the changes of an input from a Raspberry Pi with PiFace digital IO board over ZeroMQ
import zmq
import pifacedigitalio
import argparse
from time import sleep
if __name__ == "__main__":
p = argparse.ArgumentParser()
p.add_argument("input", type=int)
p.add_argument("prefix", type=str)
p.add_argument("port", type=int)
p.add_argument("--delay", type=float, default=0.1)
args = p.parse_args()
pf = pifacedigitalio.PiFaceDigital()
context = zmq.Context()
socket = context.socket(zmq.PUB)
socket.bind("tcp://*:%s" % args.port)
last_value = None
while True:
value = pf.input_pins[args.input].value
if value != last_value:
msg = "%s%s" % (args.prefix, value)
print(msg)
socket.send_string(msg)
last_value = value
sleep(args.delay)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment