Correct remote GPIO recipes

This commit is contained in:
Dave Jones
2017-07-14 14:01:29 +01:00
parent eafae5c31a
commit b2e4237a57
13 changed files with 62 additions and 44 deletions

View File

@@ -1,9 +1,11 @@
from gpiozero import LED
from gpiozero.pins.pigpio import PiGPIOPin
from gpiozero.pins.pigpio import PiGPIOFactory
from signal import pause
factory = PiGPIOFactory(host='192.168.1.3')
button = Button(2)
led = LED(PiGPIOPin(17, host='192.168.1.3'))
led = LED(17, pin_factory=factory)
led.source = button.values

View File

@@ -1,11 +1,14 @@
from gpiozero import LED
from gpiozero.pins.pigpio import PiGPIOPin
from gpiozero.pins.pigpio import PiGPIOFactory
from gpiozero.tools import all_values
from signal import pause
factory3 = PiGPIOFactory(host='192.168.1.3')
factory4 = PiGPIOFactory(host='192.168.1.3')
led = LED(17)
button_1 = Button(PiGPIOPin(17, host='192.168.1.3'))
button_2 = Button(PiGPIOPin(17, host='192.168.1.4'))
button_1 = Button(17, pin_factory=factory3)
button_2 = Button(17, pin_factory=factory4)
led.source = all_values(button_1.values, button_2.values)

View File

@@ -1,8 +1,9 @@
from gpiozero import LED
from gpiozero.pins.pigpio import PiGPIOPin
from gpiozero.pins.pigpio import PiGPIOFactory
from time import sleep
led = LED(PiGPIOPin(17, host='192.168.1.3'))
factory = PiGPIOFactory(host='192.168.1.3')
led = LED(17, pin_factory=factory)
while True:
led.on()

View File

@@ -1,9 +1,11 @@
from gpiozero import LED
from gpiozero.pins.pigpio import PiGPIOPin
from gpiozero.pins.pigpio import PiGPIOFactory
from time import sleep
led_1 = LED(PiGPIOPin(17, host='192.168.1.3'))
led_2 = LED(PiGPIOPin(17, host='192.168.1.4'))
factory3 = PiGPIOFactory(host='192.168.1.3')
factory4 = PiGPIOFactory(host='192.168.1.4')
led_1 = LED(17, pin_factory=factory3)
led_2 = LED(17, pin_factory=factory4)
while True:
led_1.on()

View File

@@ -1,9 +1,10 @@
from gpiozero import LED
from gpiozero.pins.pigpio import PiGPIOPin
from gpiozero.pins.pigpio import PiGPIOFactory
from time import sleep
remote_factory = PiGPIOFactory(host='192.168.1.3')
led_1 = LED(17) # local pin
led_2 = LED(PiGPIOPin(17, host='192.168.1.3')) # remote pin
led_2 = LED(17, pin_factory=remote_factory) # remote pin
while True:
led_1.on()

View File

@@ -1,8 +1,9 @@
from gpiozero import LED
from gpiozero.pins.rpigpio import RPiGPIOPin
from gpiozero.pins.rpigpio import RPiGPIOFactory
from time import sleep
led_1 = LED(RPiGPIOPin(17)) # local pin
local_factory = RPiGPIOFactory()
led_1 = LED(17, pin_factory=local_factory) # local pin
led_2 = LED(17) # remote pin
while True:

View File

@@ -1,10 +1,13 @@
from gpiozero import LED
from gpiozero.pins.pigpio import PiGPIOPin
from gpiozero.pins.pigpio import PiGPIOFactory
from time import sleep
factory3 = PiGPIOFactory(host='192.168.1.3')
factory4 = PiGPIOFactory(host='192.168.1.4')
led_1 = LED(17) # local pin
led_2 = LED(PiGPIOPin(17, host='192.168.1.3')) # remote pin on one pi
led_3 = LED(PiGPIOPin(17, host='192.168.1.4')) # remote pin on another pi
led_2 = LED(17, pin_factory=factory3) # remote pin on one pi
led_3 = LED(17, pin_factory=factory4) # remote pin on another pi
while True:
led_1.on()

View File

@@ -1,8 +1,9 @@
from gpiozero import LED
from gpiozero.pins.pigpio import PiGPIOPin
from gpiozero.pins.pigpio import PiGPIOFactory
from signal import pause
led = LED(PiGPIOPin(17, host='raspberrypi.local'))
factory = PiGPIOFactory(host='raspberrypi.local')
led = LED(17, pin_factory=factory)
led.blink()

View File

@@ -1,8 +1,9 @@
from gpiozero import MotionSensor
from gpiozero.pins.pigpio import PiGPIOPin
from gpiozero.pins.pigpio import PiGPIOFactory
from sense_hat import SenseHat
pir = MotionSensor(PiGPIOPin(4, host='192.168.1.4')) # remote motion sensor
remote_factory = PiGPIOFactory(host='192.198.1.4')
pir = MotionSensor(4, pin_factory=remote_factory) # remote motion sensor
sense = SenseHat() # local sense hat
while True:

View File

@@ -1,8 +1,9 @@
from gpiozero import LightSensor
from gpiozero.pins.pigpio import PiGPIOPin
from gpiozero.pins.pigpio import PiGPIOFactory
from sense_hat import SenseHat
light = LightSensor(PiGPIOPin(4, host='192.168.1.4')) # remote motion sensor
remote_factory = PiGPIOFactory(host='192.168.1.4')
light = LightSensor(4, pin_factory=remote_factory) # remote motion sensor
sense = SenseHat() # local sense hat
blue = (0, 0, 255)

View File

@@ -3,5 +3,5 @@ from gpiozero import TrafficHat
from gpiozero.pins.pigpio import PiGPIOFactory
from time import sleep
gpiozero.Device._set_pin_factory(PiGPIOFactory(host='192.168.1.3'))
gpiozero.Device.pin_factory = PiGPIOFactory(host='192.168.1.3')
th = TrafficHat() # traffic hat on 192.168.1.3 using remote pins

View File

@@ -3,6 +3,7 @@ from gpiozero import TrafficHat
from gpiozero.pins.pigpio import PiGPIOFactory
from time import sleep
remote_factory = PiGPIOFactory(host='192.168.1.3')
th_1 = TrafficHat() # traffic hat using local pins
gpiozero.Device._set_pin_factory(PiGPIOFactory(host='192.168.1.3'))
th_2 = TrafficHat() # traffic hat on 192.168.1.3 using remote pins
th_2 = TrafficHat(pin_factory=remote_factory) # traffic hat on 192.168.1.3 using remote pins