├── images ├── status-board.jpg └── status-zero.jpg ├── examples ├── button-demo │ ├── button_demo_advanced.py │ ├── button_demo_simple.py │ └── README.md ├── README.md ├── website-monitor │ ├── README.md │ ├── sz_website_advanced.py │ ├── sb_website_advanced.py │ ├── sz_website_simple.py │ └── sb_website_simple.py ├── whos-in │ ├── README.md │ ├── sz_whos_home_advanced.py │ ├── sb_whos_home_advanced.py │ ├── sz_whos_home_simple.py │ └── sb_whos_home_simple.py ├── news │ ├── README.md │ ├── sz_news_advanced.py │ ├── sb_news_advanced.py │ ├── sz_news_simple.py │ └── sb_news_simple.py ├── speedtest │ ├── README.md │ ├── sz_speedtest_advanced.py │ ├── sz_speedtest_simple.py │ ├── sb_speedtest_advanced.py │ └── sb_speedtest_simple.py ├── tube │ ├── README.md │ ├── sb_tube_advanced.py │ ├── sz_tube_advanced.py │ ├── sz_tube_simple.py │ └── sb_tube_simple.py ├── travis-build │ ├── README.md │ ├── sz_travis_advanced.py │ ├── sb_travis_advanced.py │ ├── sz_travis_simple.py │ └── sb_travis_simple.py ├── multi-room-motion │ ├── sz_motion_advanced.py │ ├── sb_motion_advanced.py │ ├── README.md │ ├── sz_motion_simple.py │ └── sb_motion_simple.py └── rain │ ├── README.md │ ├── sz_rain_advanced.py │ ├── sb_rain_advanced.py │ ├── sz_rain_simple.py │ └── sb_rain_simple.py ├── README.md └── tutorials ├── status-zero └── README.md └── status-board └── README.md /images/status-board.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThePiHut/statusboard/HEAD/images/status-board.jpg -------------------------------------------------------------------------------- /images/status-zero.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThePiHut/statusboard/HEAD/images/status-zero.jpg -------------------------------------------------------------------------------- /examples/button-demo/button_demo_advanced.py: -------------------------------------------------------------------------------- 1 | from gpiozero import StatusBoard 2 | from gpiozero.tools import negated 3 | from signal import pause 4 | 5 | sb = StatusBoard() 6 | 7 | for strip in sb: 8 | strip.lights.green.source = strip.button.values 9 | strip.lights.red.source = negated(strip.button.values) 10 | 11 | pause() 12 | -------------------------------------------------------------------------------- /examples/button-demo/button_demo_simple.py: -------------------------------------------------------------------------------- 1 | from gpiozero import StatusBoard 2 | from signal import pause 3 | 4 | sb = StatusBoard() 5 | 6 | for strip in sb: 7 | # start with all the reds on 8 | strip.lights.red.on() 9 | # when the button is pressed, toggle the lights 10 | strip.button.when_pressed = strip.lights.toggle 11 | 12 | pause() 13 | -------------------------------------------------------------------------------- /examples/button-demo/README.md: -------------------------------------------------------------------------------- 1 | # Button demo 2 | 3 | A demo for each button on the STATUS Board to toggle its strip's lights. 4 | 5 | ## Requirements 6 | 7 | None - but you'll need a STATUS Board (not STATUS Zero) as this example requires 8 | buttons. 9 | 10 | ## Code 11 | 12 | - [Simple version](button_demo_simple.py) 13 | - [Advanced version](button_demo_advanced.py) 14 | -------------------------------------------------------------------------------- /examples/README.md: -------------------------------------------------------------------------------- 1 | # STATUS examples 2 | 3 | - [Button demo](button-demo/README.md) 4 | - [Who's in?](whos-in/README.md) 5 | - [London Tube line status](tube/README.md) 6 | - [Rain in cities](rain/README.md) 7 | - [Websites up or down](website-monitor/README.md) 8 | - [Travis build status](travis-build/README.md) 9 | - [In the news](news/README.md) 10 | - [Multi-room motion sensor](multi-room-motion/README.md) 11 | - [Speedtest monitor](speedtest/README.md) 12 | -------------------------------------------------------------------------------- /examples/website-monitor/README.md: -------------------------------------------------------------------------------- 1 | # Website monitor 2 | 3 | Check whether your websites are up or down. 4 | 5 | ## Requirements 6 | 7 | You'll need the Pi to be connected to the internet. 8 | 9 | ## Code 10 | 11 | - STATUS Zero 12 | - [Simple version](sz_website_simple.py) 13 | - [Advanced version](sz_website_advanced.py) 14 | - STATUS Board 15 | - [Simple version](sb_website_simple.py) 16 | - [Advanced version](sb_website_advanced.py) 17 | -------------------------------------------------------------------------------- /examples/whos-in/README.md: -------------------------------------------------------------------------------- 1 | # Who's home indicator 2 | 3 | Check who's in the house and who's out. 4 | 5 | ## Requirements 6 | 7 | You'll need the Pi to be connected to the local network, and each person's 8 | phone will need a reserved IP address on the network. 9 | 10 | ## Code 11 | 12 | - STATUS Zero 13 | - [Simple version](sz_whos_home_simple.py) 14 | - [Advanced version](sz_whos_home_advanced.py) 15 | - STATUS Board 16 | - [Simple version](sb_whos_home_simple.py) 17 | - [Advanced version](sb_whos_home_advanced.py) 18 | -------------------------------------------------------------------------------- /examples/news/README.md: -------------------------------------------------------------------------------- 1 | # Who's in the news? 2 | 3 | Check who's mentioned on the BBC News homepage and show a green light if it's 4 | safe to look or a red if they're mentioned. 5 | 6 | ## Requirements 7 | 8 | You'll just need an internet connection. 9 | 10 | Choose the names or terms you want to monitor. 11 | 12 | ## Code 13 | 14 | - STATUS Zero 15 | - [Simple example](sz_news_simple.py) 16 | - [Advanced example](sz_news_advanced.py) 17 | - STATUS Board 18 | - [Simple example](sb_news_simple.py) 19 | - [Advanced example](sb_news_advanced.py) 20 | -------------------------------------------------------------------------------- /examples/speedtest/README.md: -------------------------------------------------------------------------------- 1 | # Speedtest monitor 2 | 3 | Show your upload and download speed on a STATUS board. 4 | 5 | ## Requirements 6 | 7 | You will need to be connected to the internet, and you will need to install the 8 | `speedtest` library: 9 | 10 | ```bash 11 | sudo pip3 install speedtest-cli 12 | ``` 13 | 14 | ## Code 15 | 16 | - STATUS Zero 17 | - [Simple version](sz_speedtest_simple.py) 18 | - [Advanced version](sz_speedtest_advanced.py) 19 | - STATUS Board 20 | - [Simple version](sb_speedtest_simple.py) 21 | - [Advanced version](sb_speedtest_advanced.py) 22 | -------------------------------------------------------------------------------- /examples/tube/README.md: -------------------------------------------------------------------------------- 1 | # London tube line status 2 | 3 | Show the status of a set of London tube lines. Are they running a good service 4 | or are there delays? 5 | 6 | ## Requirements 7 | 8 | You will need to be connected to the internet, and you will need to install the 9 | `tubestatus` library: 10 | 11 | ```bash 12 | sudo pip3 install tubestatus 13 | ``` 14 | 15 | ## Code 16 | 17 | - STATUS Zero 18 | - [Simple version](sz_tube_simple.py) 19 | - [Advanced version](sz_tube_advanced.py) 20 | - STATUS Board 21 | - [Simple version](sb_tube_simple.py) 22 | - [Advanced version](sb_tube_advanced.py) 23 | -------------------------------------------------------------------------------- /examples/whos-in/sz_whos_home_advanced.py: -------------------------------------------------------------------------------- 1 | from gpiozero import StatusZero, PingServer 2 | from gpiozero.tools import negated, smoothed 3 | from signal import pause 4 | 5 | sz = StatusZero('mum', 'dad', 'alice') 6 | 7 | statuses = { 8 | PingServer('192.168.1.5'): sz.mum, 9 | PingServer('192.168.1.6'): sz.dad, 10 | PingServer('192.168.1.7'): sz.alice, 11 | } 12 | 13 | for server, strip in statuses.items(): 14 | strip.green.source = smoothed(server.values, 2, any) # allow 1 false negative out of 2 15 | strip.green.source_delay = 60 16 | strip.red.source = negated(strip.green.values) 17 | 18 | pause() 19 | -------------------------------------------------------------------------------- /examples/news/sz_news_advanced.py: -------------------------------------------------------------------------------- 1 | from gpiozero import StatusZero 2 | from gpiozero.tools import negated 3 | import requests 4 | from signal import pause 5 | 6 | def in_the_news(text): 7 | url = 'http://www.bbc.co.uk/news' 8 | while True: 9 | r = requests.get(url) 10 | yield text in r.text 11 | 12 | sz = StatusZero() 13 | 14 | people = ['Donald Trump', 'Kim Jong-Un', 'Theresa May'] 15 | 16 | for strip, person in zip(sz, people): 17 | strip.red.source = in_the_news(person) 18 | strip.red.source_delay = 60 # check every hour 19 | strip.green.source = negated(strip.red.values) 20 | 21 | pause() 22 | -------------------------------------------------------------------------------- /examples/whos-in/sb_whos_home_advanced.py: -------------------------------------------------------------------------------- 1 | from gpiozero import StatusBoard, PingServer 2 | from gpiozero.tools import negated, smoothed 3 | from signal import pause 4 | 5 | sb = StatusBoard('mum', 'dad', 'alice') 6 | 7 | statuses = { 8 | PingServer('192.168.1.5'): sb.mum, 9 | PingServer('192.168.1.6'): sb.dad, 10 | PingServer('192.168.1.7'): sb.alice, 11 | } 12 | 13 | for server, strip in statuses.items(): 14 | strip.lights.green.source = smoothed(server.values, 2, any) # allow 1 false negative out of 2 15 | strip.lights.green.source_delay = 60 16 | strip.lights.red.source = negated(strip.lights.green.values) 17 | 18 | pause() 19 | -------------------------------------------------------------------------------- /examples/news/sb_news_advanced.py: -------------------------------------------------------------------------------- 1 | from gpiozero import StatusBoard 2 | from gpiozero.tools import negated 3 | import requests 4 | from signal import pause 5 | 6 | def in_the_news(text): 7 | url = 'http://www.bbc.co.uk/news' 8 | while True: 9 | r = requests.get(url) 10 | yield text in r.text 11 | 12 | sb = StatusBoard() 13 | 14 | people = ['Donald Trump', 'Kim Jong-Un', 'Theresa May'] 15 | 16 | for strip, person in zip(sb, people): 17 | strip.lights.red.source = in_the_news(person) 18 | strip.lights.red.source_delay = 60 # check every hour 19 | strip.lights.green.source = negated(strip.lights.red.values) 20 | 21 | pause() 22 | -------------------------------------------------------------------------------- /examples/travis-build/README.md: -------------------------------------------------------------------------------- 1 | # Travis build status 2 | 3 | Check the build status of your GitHub projects on Travis CI. 4 | 5 | ## Requirements 6 | 7 | You'll need the Pi to be connected to the internet. 8 | 9 | You'll need to install `travispy`: 10 | 11 | ```bash 12 | sudo pip3 install travispy 13 | ``` 14 | 15 | You'll need to set up the repositories on [Travis CI](https://travis-ci.org/). 16 | 17 | ## Code 18 | 19 | - STATUS Zero 20 | - [Simple example](sz_travis_simple.py) 21 | - [Advanced example](sz_travis_advanced.py) 22 | - STATUS Board 23 | - [Simple example](sb_travis_simple.py) 24 | - [Advanced example](sb_travis_advanced.py) 25 | -------------------------------------------------------------------------------- /examples/tube/sb_tube_advanced.py: -------------------------------------------------------------------------------- 1 | from tubestatus import Status 2 | from gpiozero import StatusBoard 3 | from time import sleep 4 | 5 | tube = Status() 6 | lines = ['Central', 'Northern', 'Piccadilly'] 7 | 8 | sz = StatusBoard() 9 | 10 | while True: 11 | for strip, line in zip(sz, lines): 12 | status = tube.get_status(line) 13 | { 14 | 'Good Service': strip.green.on, 15 | 'Minor Delays': strip.green.blink, 16 | 'Severe Delays': strip.red.on, 17 | 'Part Closure': strip.red.blink, 18 | 'Service Closed': strip.off, 19 | }[status.description]() 20 | sleep(60) # check every minute 21 | -------------------------------------------------------------------------------- /examples/multi-room-motion/sz_motion_advanced.py: -------------------------------------------------------------------------------- 1 | from gpiozero import StatusZero, MotionSensor 2 | from gpiozero.pins.pigpio import PiGPIOFactory 3 | from gpiozero.tools import negated 4 | from signal import pause 5 | 6 | ips = ['192.168.1.3', '192.168.1.4', '192.168.1.5'] 7 | remotes = [PiGPIOFactory(host=ip) for ip in ips] 8 | 9 | sz = StatusZero() # on this pi 10 | sensors = [MotionSensor(17, pin_factory=r) for r in remotes] # remote sensors 11 | 12 | for strip, sensor in zip(sz, sensors): 13 | strip.green.source = sensor.values 14 | strip.green.source_delay = 5 # check every 5 seconds 15 | strip.red.source = negated(strip.green.values) 16 | 17 | pause() 18 | -------------------------------------------------------------------------------- /examples/speedtest/sz_speedtest_advanced.py: -------------------------------------------------------------------------------- 1 | from gpiozero import StatusZero 2 | from speedtest import Speedtest 3 | from time import sleep 4 | 5 | sz = StatusZero() 6 | 7 | st = Speedtest() 8 | 9 | def update(): 10 | while True: 11 | st.get_best_server() 12 | 13 | down = st.download() 14 | up = st.upload() 15 | 16 | yield ( 17 | (up > 2000000, down > 2000000), 18 | (up > 4000000, down > 4000000), 19 | (up > 6000000, down > 6000000), 20 | ) 21 | 22 | sz.source = update() 23 | sz.source_delay = 60*10 # check every 10 minutes 24 | 25 | while True: 26 | print(tuple(sz.value)) 27 | sleep(1) 28 | -------------------------------------------------------------------------------- /examples/travis-build/sz_travis_advanced.py: -------------------------------------------------------------------------------- 1 | from travispy import TravisPy 2 | from gpiozero import StatusZero 3 | from gpiozero.tools import negated 4 | from time import sleep 5 | from signal import pause 6 | 7 | def build_passed(repo): 8 | t = TravisPy() 9 | r = t.repo(repo) 10 | while True: 11 | yield r.last_build_state == 'passed' 12 | 13 | sz = StatusZero() 14 | 15 | repos = ['RPi-Distro/python-gpiozero', 'raspberrypi/documentation'] 16 | 17 | for strip, repo in zip(sz, repos): 18 | strip.green.source = build_passed(repo) 19 | strip.green.source_delay = 60 * 5 # check every 5 minutes 20 | strip.red.source = negated(strip.green.values) 21 | 22 | pause() 23 | -------------------------------------------------------------------------------- /examples/multi-room-motion/sb_motion_advanced.py: -------------------------------------------------------------------------------- 1 | from gpiozero import StatusBoard, MotionSensor 2 | from gpiozero.pins.pigpio import PiGPIOFactory 3 | from gpiozero.tools import negated 4 | from signal import pause 5 | 6 | ips = ['192.168.1.3', '192.168.1.4', '192.168.1.5'] 7 | remotes = [PiGPIOFactory(host=ip) for ip in ips] 8 | 9 | sb = StatusBoard() # on this pi 10 | sensors = [MotionSensor(17, pin_factory=r) for r in remotes] # remote sensors 11 | 12 | for strip, sensor in zip(sb, sensors): 13 | strip.lights.green.source = sensor.values 14 | strip.lights.green.source_delay = 5 # check every 5 seconds 15 | strip.lights.red.source = negated(strip.lights.green.values) 16 | 17 | pause() 18 | -------------------------------------------------------------------------------- /examples/travis-build/sb_travis_advanced.py: -------------------------------------------------------------------------------- 1 | from travispy import TravisPy 2 | from gpiozero import StatusBoard 3 | from gpiozero.tools import negated 4 | from time import sleep 5 | from signal import pause 6 | 7 | def build_passed(repo): 8 | t = TravisPy() 9 | r = t.repo(repo) 10 | while True: 11 | yield r.last_build_state == 'passed' 12 | 13 | sb = StatusBoard() 14 | 15 | repos = ['RPi-Distro/python-gpiozero', 'raspberrypi/documentation'] 16 | 17 | for strip, repo in zip(sb, repos): 18 | strip.lights.green.source = build_passed(repo) 19 | strip.lights.green.source_delay = 60 * 5 # check every 5 minutes 20 | strip.lights.red.source = negated(strip.lights.green.values) 21 | 22 | pause() 23 | -------------------------------------------------------------------------------- /examples/tube/sz_tube_advanced.py: -------------------------------------------------------------------------------- 1 | from tubestatus import Status 2 | from gpiozero import StatusZero 3 | from time import sleep 4 | 5 | tube = Status() 6 | lines = ['Central', 'Northern', 'Piccadilly'] 7 | 8 | sz = StatusZero() 9 | 10 | while True: 11 | for strip, line in zip(sz, lines): 12 | status = tube.get_status(line) 13 | action = { 14 | 'Good Service': strip.green.on, 15 | 'Minor Delays': strip.green.blink, 16 | 'Severe Delays': strip.red.on, 17 | 'Part Closure': strip.red.blink, 18 | 'Service Closed': strip.off, 19 | }[status.description] 20 | strip.off() 21 | action() 22 | sleep(60) # check every minute 23 | -------------------------------------------------------------------------------- /examples/speedtest/sz_speedtest_simple.py: -------------------------------------------------------------------------------- 1 | from gpiozero import StatusZero 2 | from speedtest import Speedtest 3 | from time import sleep 4 | 5 | sz = StatusZero() 6 | 7 | st = Speedtest() 8 | 9 | while True: 10 | st.get_best_server() 11 | 12 | down = st.download() 13 | if down > 60000000: # 60Mb 14 | sz.one.green.on() 15 | if down > 40000000: # 40Mb 16 | sz.two.green.on() 17 | if down > 20000000: # 20Mb 18 | sz.three.green.on() 19 | 20 | up = st.upload() 21 | if up > 60000000: # 6Mb 22 | sz.one.red.on() 23 | if up > 4000000: # 4Mb 24 | sz.two.red.on() 25 | if up > 2000000: # 2Mb 26 | sz.three.red.on() 27 | 28 | sleep(60*10) # check every 10 minutes 29 | -------------------------------------------------------------------------------- /examples/speedtest/sb_speedtest_advanced.py: -------------------------------------------------------------------------------- 1 | from gpiozero import StatusZero 2 | from speedtest import Speedtest 3 | from time import sleep 4 | 5 | sb = StatusZero() 6 | 7 | st = Speedtest() 8 | 9 | def update(): 10 | while True: 11 | st.get_best_server() 12 | 13 | down = st.download() 14 | up = st.upload() 15 | 16 | yield ( 17 | (None, (up > 1000000, down > 1000000)), 18 | (None, (up > 3000000, down > 3000000)), 19 | (None, (up > 5000000, down > 5000000)), 20 | (None, (up > 7000000, down > 7000000)), 21 | (None, (up > 9000000, down > 9000000)), 22 | ) 23 | 24 | sb.source = update() 25 | sb.source_delay = 60*10 # check every 10 minutes 26 | 27 | while True: 28 | print(tuple(sb.value)) 29 | sleep(1) 30 | -------------------------------------------------------------------------------- /examples/travis-build/sz_travis_simple.py: -------------------------------------------------------------------------------- 1 | from travispy import TravisPy 2 | from gpiozero import StatusZero 3 | from time import sleep 4 | 5 | def build_passed(repo): 6 | t = TravisPy() 7 | r = t.repo(repo) 8 | return r.last_build_state == 'passed' 9 | 10 | sz = StatusZero('gpiozero', 'documentation') 11 | 12 | while True: 13 | if build_passed('RPi-Distro/python-gpiozero'): 14 | sz.gpiozero.green.on() 15 | sz.gpiozero.red.off() 16 | else: 17 | sz.gpiozero.red.on() 18 | sz.gpiozero.green.off() 19 | 20 | if build_passed('raspberrypi/documentation'): 21 | sz.documentation.green.on() 22 | sz.documentation.red.off() 23 | else: 24 | sz.documentation.red.on() 25 | sz.documentation.green.off() 26 | 27 | sleep(60*5) # check every 5 minutes 28 | -------------------------------------------------------------------------------- /examples/whos-in/sz_whos_home_simple.py: -------------------------------------------------------------------------------- 1 | from gpiozero import StatusZero, PingServer 2 | from time import sleep 3 | 4 | sz = StatusZero('mum', 'dad', 'alice') 5 | 6 | mum = PingServer('192.168.1.3') 7 | dad = PingServer('192.168.1.4') 8 | alice = PingServer('192.168.1.5') 9 | 10 | while True: 11 | if mum.is_active: 12 | sz.mum.green.on() 13 | sz.mum.red.off() 14 | else: 15 | sz.mum.red.on() 16 | sz.mum.green.off() 17 | 18 | if dad.is_active: 19 | sz.dad.green.on() 20 | sz.dad.red.off() 21 | else: 22 | sz.dad.red.on() 23 | sz.dad.green.off() 24 | 25 | if alice.is_active: 26 | sz.alice.green.on() 27 | sz.alice.red.off() 28 | else: 29 | sz.alice.red.on() 30 | sz.alice.green.off() 31 | 32 | sleep(60) # check every minute 33 | -------------------------------------------------------------------------------- /examples/travis-build/sb_travis_simple.py: -------------------------------------------------------------------------------- 1 | from travispy import TravisPy 2 | from gpiozero import StatusBoard 3 | from time import sleep 4 | 5 | def build_passed(repo): 6 | t = TravisPy() 7 | r = t.repo(repo) 8 | return r.last_build_state == 'passed' 9 | 10 | sb = StatusBoard('gpiozero', 'documentation') 11 | 12 | while True: 13 | if build_passed('RPi-Distro/python-gpiozero'): 14 | sb.gpiozero.lights.green.on() 15 | sb.gpiozero.lights.red.off() 16 | else: 17 | sb.gpiozero.lights.red.on() 18 | sb.gpiozero.lights.green.off() 19 | 20 | if build_passed('raspberrypi/documentation'): 21 | sb.documentation.lights.green.on() 22 | sb.documentation.lights.red.off() 23 | else: 24 | sb.documentation.lights.red.on() 25 | sb.documentation.lights.green.off() 26 | 27 | sleep(60*5) # check every 5 minutes 28 | -------------------------------------------------------------------------------- /examples/news/sz_news_simple.py: -------------------------------------------------------------------------------- 1 | from gpiozero import StatusZero 2 | import requests 3 | from time import sleep 4 | 5 | def in_the_news(text): 6 | url = 'http://www.bbc.co.uk/news' 7 | r = requests.get(url) 8 | return text in r.text 9 | 10 | sz = StatusZero('trump', 'kim', 'may') 11 | 12 | while True: 13 | if in_the_news('Donald Trump'): 14 | sz.trump.red.on() 15 | sz.trump.green.off() 16 | else: 17 | sz.trump.green.on() 18 | sz.trump.red.off() 19 | 20 | if in_the_news('Kim Jong-Un'): 21 | sz.kim.red.on() 22 | sz.kim.green.off() 23 | else: 24 | sz.kim.green.on() 25 | sz.kim.red.off() 26 | 27 | if in_the_news('Theresa May'): 28 | sz.may.red.on() 29 | sz.may.green.off() 30 | else: 31 | sz.may.green.on() 32 | sz.may.red.off() 33 | 34 | sleep(60*60) # check every hour 35 | -------------------------------------------------------------------------------- /examples/rain/README.md: -------------------------------------------------------------------------------- 1 | # Rain in cities 2 | 3 | Check whether it's raining in given cities! 4 | 5 | ## Requirements 6 | 7 | You'll need an API key from [openweathermap.org](http://openweathermap.org/). 8 | 9 | Paste this key into the `KEY` variable in the Python file. 10 | 11 | You'll also need to download the `cities.json` file: 12 | 13 | ```bash 14 | wget https://goo.gl/qpTF6n -O cities.json 15 | ``` 16 | 17 | Just edit the names of cities to the ones you want to monitor. 18 | 19 | ## Code 20 | 21 | - STATUS Zero 22 | - [Simple version](sz_rain_simple.py) 23 | - [Advanced version](sz_rain_advanced.py) 24 | - STATUS Board 25 | - [Simple version](sb_rain_simple.py) 26 | - [Advanced version](sb_rain_advanced.py) 27 | 28 | ## More 29 | 30 | For more weather data, see the [Dress for the weather](https://projects.raspberrypi.org/en/projects/dress-for-the-weather) 31 | project on the Raspberry Pi website 32 | -------------------------------------------------------------------------------- /examples/whos-in/sb_whos_home_simple.py: -------------------------------------------------------------------------------- 1 | from gpiozero import StatusBoard, PingServer 2 | from time import sleep 3 | 4 | sb = StatusBoard('mum', 'dad', 'alice') 5 | 6 | mum = PingServer('192.168.1.3') 7 | dad = PingServer('192.168.1.4') 8 | alice = PingServer('192.168.1.5') 9 | 10 | while True: 11 | if mum.is_active: 12 | sb.mum.lights.green.on() 13 | sb.mum.lights.red.off() 14 | else: 15 | sb.mum.lights.red.on() 16 | sb.mum.lights.green.off() 17 | 18 | if dad.is_active: 19 | sb.dad.lights.green.on() 20 | sb.dad.lights.red.off() 21 | else: 22 | sb.dad.lights.red.on() 23 | sb.dad.lights.green.off() 24 | 25 | if alice.is_active: 26 | sb.alice.lights.green.on() 27 | sb.alice.lights.red.off() 28 | else: 29 | sb.alice.lights.red.on() 30 | sb.alice.lights.green.off() 31 | 32 | sleep(60) # check every minute 33 | -------------------------------------------------------------------------------- /examples/rain/sz_rain_advanced.py: -------------------------------------------------------------------------------- 1 | from gpiozero import StatusZero 2 | from gpiozero.tools import negated 3 | import json 4 | import requests 5 | from signal import pause 6 | 7 | KEY = 'ENTER API KEY HERE' # http://openweathermap.org/ 8 | BASE_URL = 'http://api.openweathermap.org/data/2.5/forecast?APPID={}'.format(KEY) 9 | 10 | with open('cities.json') as f: 11 | cities = json.load(f) 12 | 13 | def is_raining(city, country): 14 | city_id = cities[country][city] 15 | url = '{}&id={}'.format(BASE_URL, city_id) 16 | while True: 17 | j = requests.get(url).json() 18 | yield 'rain' in j['list'][2] 19 | 20 | sz = StatusZero() 21 | 22 | my_cities = ['cambridge', 'sheffield', 'nottingham'] 23 | 24 | for strip, city in zip(sz, my_cities): 25 | strip.red.source = is_raining(city, 'GB') 26 | strip.red.source_delay = 60*60 # check every hour 27 | strip.green.source = negated(strip.red.values) 28 | 29 | pause() 30 | -------------------------------------------------------------------------------- /examples/rain/sb_rain_advanced.py: -------------------------------------------------------------------------------- 1 | from gpiozero import StatusBoard 2 | from gpiozero.tools import negated 3 | import json 4 | import requests 5 | from signal import pause 6 | 7 | KEY = 'ENTER API KEY HERE' # http://openweathermap.org/ 8 | BASE_URL = 'http://api.openweathermap.org/data/2.5/forecast?APPID={}'.format(KEY) 9 | 10 | with open('cities.json') as f: 11 | cities = json.load(f) 12 | 13 | def is_raining(city, country): 14 | city_id = cities[country][city] 15 | url = '{}&id={}'.format(BASE_URL, city_id) 16 | while True: 17 | j = requests.get(url).json() 18 | yield 'rain' in j['list'][2] 19 | 20 | sb = StatusBoard() 21 | 22 | my_cities = ['cambridge', 'sheffield', 'nottingham'] 23 | 24 | for strip, city in zip(sb, my_cities): 25 | strip.lights.red.source = is_raining(city, 'GB') 26 | strip.lights.red.source_delay = 60*60 # check every hour 27 | strip.lights.green.source = negated(strip.lights.red.values) 28 | 29 | pause() 30 | -------------------------------------------------------------------------------- /examples/news/sb_news_simple.py: -------------------------------------------------------------------------------- 1 | from gpiozero import StatusBoard 2 | import requests 3 | from time import sleep 4 | 5 | def in_the_news(text): 6 | url = 'http://www.bbc.co.uk/news' 7 | r = requests.get(url) 8 | return text in r.text 9 | 10 | sb = StatusBoard('trump', 'kim', 'may') 11 | 12 | while True: 13 | if in_the_news('Donald Trump'): 14 | sb.trump.lights.red.on() 15 | sb.trump.lights.green.off() 16 | else: 17 | sb.trump.lights.green.on() 18 | sb.trump.lights.red.off() 19 | 20 | if in_the_news('Kim Jong-Un'): 21 | sb.kim.lights.red.on() 22 | sb.kim.lights.green.off() 23 | else: 24 | sb.kim.lights.green.on() 25 | sb.kim.lights.red.off() 26 | 27 | if in_the_news('Theresa May'): 28 | sb.may.lights.red.on() 29 | sb.may.lights.green.off() 30 | else: 31 | sb.may.lights.green.on() 32 | sb.may.lights.red.off() 33 | 34 | sleep(60*60) # check every hour 35 | -------------------------------------------------------------------------------- /examples/speedtest/sb_speedtest_simple.py: -------------------------------------------------------------------------------- 1 | from gpiozero import StatusBoard 2 | from speedtest import Speedtest 3 | from time import sleep 4 | 5 | sb = StatusBoard() 6 | 7 | st = Speedtest() 8 | 9 | while True: 10 | st.get_best_server() 11 | 12 | down = st.download() 13 | if down > 90000000: # 90Mb 14 | sb.one.lights.green.on() 15 | if down > 70000000: # 70Mb 16 | sb.two.lights.green.on() 17 | if down > 50000000: # 50Mb 18 | sb.three.lights.green.on() 19 | if down > 30000000: # 30Mb 20 | sb.four.lights.green.on() 21 | if down > 10000000: # 10Mb 22 | sb.five.lights.green.on() 23 | 24 | up = st.upload() 25 | if up > 90000000: # 9Mb 26 | sb.one.lights.red.on() 27 | if up > 7000000: # 7Mb 28 | sb.two.lights.red.on() 29 | if up > 5000000: # 5Mb 30 | sb.three.lights.red.on() 31 | if up > 3000000: # 3Mb 32 | sb.four.lights.red.on() 33 | if up > 1000000: # 1Mb 34 | sb.five.lights.red.on() 35 | 36 | sleep(60*10) # check every 10 minutes 37 | -------------------------------------------------------------------------------- /examples/website-monitor/sz_website_advanced.py: -------------------------------------------------------------------------------- 1 | from gpiozero import StatusZero 2 | from gpiozero.tools import negated, smoothed 3 | import requests 4 | from time import sleep 5 | 6 | sz = StatusZero('raspberrypi', 'codeclub', 'coderdojo') 7 | 8 | def website_up(url): 9 | while True: 10 | try: 11 | r = requests.get(url) 12 | yield r.ok 13 | except: 14 | yield False 15 | 16 | statuses = { 17 | sz.raspberrypi: website_up('https://www.raspberrypi.org/'), 18 | sz.codeclub: website_up('https://www.codeclub.org.uk/'), 19 | sz.coderdojo: website_up('https://www.coderdojo.com/'), 20 | } 21 | 22 | for strip, website in statuses.items(): 23 | strip.green.source = smoothed(website, 2, any) # allow 1 false negative out of 2 24 | strip.green.source_delay = 60 25 | strip.red.source = negated(strip.green.values) 26 | strip.red.source_delay = 60 27 | 28 | google = website_up('https://www.google.com/') 29 | 30 | for google_up in google: 31 | if not google_up: 32 | sz.blink() 33 | sleep(60) 34 | -------------------------------------------------------------------------------- /examples/multi-room-motion/README.md: -------------------------------------------------------------------------------- 1 | # Multi-room motion sensor 2 | 3 | Set up multiple Pis around the house with PIR motion sensors attached and use 4 | the STATUS Zero to show which room has motion so you can tell where people are 5 | in the house. 6 | 7 | ## Requirements 8 | 9 | You'll need a Pi (a Pi Zero W would be ideal) in each room you want to monitor. 10 | Each Pi will need to be on the local network. You'll need a PIR motion sensor 11 | connected to each one, and each Pi will need to be running Raspbian with the 12 | pigpio daemon running. No Python code is required on the remote Pis. See the 13 | [GPIO Zero remote GPIO](http://gpiozero.readthedocs.io/en/stable/remote_gpio.html) 14 | documentation for more information. 15 | 16 | ## Code 17 | 18 | You will need to run the Python code on the Pi with the Status Zero attached. 19 | 20 | - STATUS Zero 21 | - [Simple version](sz_motion_simple.py) 22 | - [Advanced version](sz_motion_advanced.py) 23 | - STATUS Board 24 | - [Simple version](sb_motion_simple.py) 25 | - [Advanced version](sb_motion_advanced.py) 26 | -------------------------------------------------------------------------------- /examples/website-monitor/sb_website_advanced.py: -------------------------------------------------------------------------------- 1 | from gpiozero import StatusBoard 2 | from gpiozero.tools import negated, smoothed 3 | import requests 4 | from time import sleep 5 | 6 | sb = StatusBoard('raspberrypi', 'codeclub', 'coderdojo') 7 | 8 | def website_up(url): 9 | while True: 10 | try: 11 | r = requests.get(url) 12 | yield r.ok 13 | except: 14 | yield False 15 | 16 | statuses = { 17 | sb.raspberrypi: website_up('https://www.raspberrypi.org/'), 18 | sb.codeclub: website_up('https://www.codeclub.org.uk/'), 19 | sb.coderdojo: website_up('https://www.coderdojo.com/'), 20 | } 21 | 22 | for strip, website in statuses.items(): 23 | strip.lights.green.source = smoothed(website, 2, any) # allow 1 false negative out of 2 24 | strip.lights.green.source_delay = 60 25 | strip.lights.red.source = negated(strip.lights.green.values) 26 | strip.lights.red.source_delay = 60 27 | 28 | google = website_up('https://www.google.com/') 29 | 30 | for google_up in google: 31 | if not google_up: 32 | for strip in sb: 33 | strip.lights.blink() 34 | sleep(60) 35 | -------------------------------------------------------------------------------- /examples/website-monitor/sz_website_simple.py: -------------------------------------------------------------------------------- 1 | from gpiozero import StatusZero 2 | import requests 3 | from time import sleep 4 | 5 | def website_up(url): 6 | try: 7 | r = requests.get(url) 8 | return r.ok 9 | except: 10 | return False 11 | 12 | sz = StatusZero('raspberrypi', 'codeclub', 'coderdojo') 13 | 14 | while True: 15 | if website_up('https://www.google.com/'): 16 | if website_up('https://www.raspberrypi.org/'): 17 | sz.raspberrypi.green.on() 18 | sz.raspberrypi.red.off() 19 | else: 20 | sz.raspberrypi.red.on() 21 | sz.raspberrypi.green.off() 22 | 23 | if website_up('https://www.codeclub.org.uk/'): 24 | sz.codeclub.green.on() 25 | sz.codeclub.red.off() 26 | else: 27 | sz.codeclub.red.on() 28 | sz.codeclub.green.off() 29 | 30 | if website_up('https://www.coderdojo.com/'): 31 | sz.coderdojo.green.on() 32 | sz.coderdojo.red.off() 33 | else: 34 | sz.coderdojo.red.on() 35 | sz.coderdojo.green.off() 36 | else: 37 | sz.blink() # internet down, blink everything 38 | 39 | sleep(60*60) # check every hour 40 | -------------------------------------------------------------------------------- /examples/multi-room-motion/sz_motion_simple.py: -------------------------------------------------------------------------------- 1 | from gpiozero import StatusZero, MotionSensor 2 | from gpiozero.pins.pigpio import PiGPIOFactory 3 | from gpiozero.tools import negated 4 | from signal import pause 5 | 6 | living_room_pi = PiGPIOFactory(host='192.168.1.3') 7 | dining_room_pi = PiGPIOFactory(host='192.168.1.4') 8 | bedroom_pi = PiGPIOFactory(host='192.168.1.5') 9 | 10 | sz = StatusZero('living_room', 'dining_room', 'bedroom') # on this pi 11 | living_room = MotionSensor(17, pin_factory=living_room_pi) # remote sensors 12 | dining_room = MotionSensor(17, pin_factory=dining_room_pi) 13 | bedroom = MotionSensor(17, pin_factory=bedroom_pi) 14 | 15 | while True: 16 | if living_room.motion_detected: 17 | sz.living_room.green.on() 18 | sz.living_room.red.off() 19 | else: 20 | sz.living_room.red.on() 21 | sz.living_room.green.off() 22 | 23 | if dining_room.motion_detected: 24 | sz.dining_room.green.on() 25 | sz.dining_room.red.off() 26 | else: 27 | sz.dining_room.red.on() 28 | sz.dining_room.green.off() 29 | 30 | if bedroom.motion_detected: 31 | sz.bedroom.green.on() 32 | sz.bedroom.red.off() 33 | else: 34 | sz.bedroom.red.on() 35 | sz.bedroom.green.off() 36 | 37 | sleep(5) 38 | -------------------------------------------------------------------------------- /examples/rain/sz_rain_simple.py: -------------------------------------------------------------------------------- 1 | from gpiozero import StatusZero 2 | from gpiozero.tools import negated 3 | import json 4 | import requests 5 | from time import sleep 6 | 7 | KEY = 'ENTER API KEY HERE' # http://openweathermap.org/ 8 | BASE_URL = 'http://api.openweathermap.org/data/2.5/forecast?APPID={}'.format(KEY) 9 | 10 | with open('cities.json') as f: 11 | cities = json.load(f) 12 | 13 | def is_raining(city, country): 14 | city_id = cities[country][city] 15 | url = '{}&id={}'.format(BASE_URL, city_id) 16 | j = requests.get(url).json() 17 | return 'rain' in j['list'][2] 18 | 19 | sz = StatusZero('cambridge', 'sheffield', 'nottingham') 20 | 21 | while True: 22 | if is_raining('Cambridge', 'GB'): 23 | sz.cambridge.red.on() 24 | sz.cambridge.green.off() 25 | else: 26 | sz.cambridge.green.on() 27 | sz.cambridge.red.off() 28 | 29 | if is_raining('Sheffield', 'GB'): 30 | sz.sheffield.red.on() 31 | sz.sheffield.green.off() 32 | else: 33 | sz.sheffield.green.on() 34 | sz.sheffield.red.off() 35 | 36 | if is_raining('nottingham', 'GB'): 37 | sz.nottingham.red.on() 38 | sz.nottingham.green.off() 39 | else: 40 | sz.nottingham.green.on() 41 | sz.nottingham.red.off() 42 | 43 | sleep(60*60) # check every hour 44 | -------------------------------------------------------------------------------- /examples/website-monitor/sb_website_simple.py: -------------------------------------------------------------------------------- 1 | from gpiozero import StatusBoard 2 | import requests 3 | from time import sleep 4 | 5 | def website_up(url): 6 | try: 7 | r = requests.get(url) 8 | return r.ok 9 | except: 10 | return False 11 | 12 | sb = StatusBoard('raspberrypi', 'codeclub', 'coderdojo') 13 | 14 | while True: 15 | if website_up('https://www.google.com/'): 16 | if website_up('https://www.raspberrypi.org/'): 17 | sb.raspberrypi.lights.green.on() 18 | sb.raspberrypi.lights.red.off() 19 | else: 20 | sb.raspberrypi.lights.red.on() 21 | sb.raspberrypi.lights.green.off() 22 | 23 | if website_up('https://www.codeclub.org.uk/'): 24 | sb.codeclub.lights.green.on() 25 | sb.codeclub.lights.red.off() 26 | else: 27 | sb.codeclub.lights.red.on() 28 | sb.codeclub.lights.green.off() 29 | 30 | if website_up('https://www.coderdojo.com/'): 31 | sb.coderdojo.lights.green.on() 32 | sb.coderdojo.lights.red.off() 33 | else: 34 | sb.coderdojo.lights.red.on() 35 | sb.coderdojo.lights.green.off() 36 | else: 37 | for strip in sb: 38 | strip.lights.blink() # internet down, blink everything 39 | 40 | sleep(60*60) # check every hour 41 | -------------------------------------------------------------------------------- /examples/rain/sb_rain_simple.py: -------------------------------------------------------------------------------- 1 | from gpiozero import StatusBoard 2 | import json 3 | import requests 4 | from time import sleep 5 | 6 | KEY = 'ENTER API KEY HERE' # http://openweathermap.org/ 7 | BASE_URL = 'http://api.openweathermap.org/data/2.5/forecast?APPID={}'.format(KEY) 8 | 9 | with open('cities.json') as f: 10 | cities = json.load(f) 11 | 12 | def is_raining(city, country): 13 | city_id = cities[country][city] 14 | url = '{}&id={}'.format(BASE_URL, city_id) 15 | j = requests.get(url).json() 16 | return 'rain' in j['list'][2] 17 | 18 | sb = StatusBoard('cambridge', 'sheffield', 'nottingham') 19 | 20 | while True: 21 | if is_raining('Cambridge', 'GB'): 22 | sb.cambridge.lights.red.on() 23 | sb.cambridge.lights.green.off() 24 | else: 25 | sb.cambridge.lights.green.on() 26 | sb.cambridge.lights.red.off() 27 | 28 | if is_raining('Sheffield', 'GB'): 29 | sb.sheffield.lights.red.on() 30 | sb.sheffield.lights.green.off() 31 | else: 32 | sb.sheffield.lights.green.on() 33 | sb.sheffield.lights.red.off() 34 | 35 | if is_raining('Nottingham', 'GB'): 36 | sb.nottingham.lights.red.on() 37 | sb.nottingham.lights.green.off() 38 | else: 39 | sb.nottingham.lights.green.on() 40 | sb.nottingham.lights.red.off() 41 | 42 | sleep(60*60) # check every hour 43 | -------------------------------------------------------------------------------- /examples/multi-room-motion/sb_motion_simple.py: -------------------------------------------------------------------------------- 1 | from gpiozero import StatusBoard, MotionSensor 2 | from gpiozero.pins.pigpio import PiGPIOFactory 3 | from gpiozero.tools import negated 4 | from signal import pause 5 | 6 | living_room_pi = PiGPIOFactory(host='192.168.1.3') 7 | dining_room_pi = PiGPIOFactory(host='192.168.1.4') 8 | bedroom_pi = PiGPIOFactory(host='192.168.1.5') 9 | 10 | sb = StatusBoard('living_room', 'dining_room', 'bedroom') # on this pi 11 | living_room = MotionSensor(17, pin_factory=living_room_pi) # remote sensors 12 | dining_room = MotionSensor(17, pin_factory=dining_room_pi) 13 | bedroom = MotionSensor(17, pin_factory=bedroom_pi) 14 | 15 | while True: 16 | if living_room.motion_detected: 17 | sb.living_room.lights.green.on() 18 | sb.living_room.lights.red.off() 19 | else: 20 | sb.living_room.lights.red.on() 21 | sb.living_room.lights.green.off() 22 | 23 | if dining_room.motion_detected: 24 | sb.dining_room.lights.green.on() 25 | sb.dining_room.lights.red.off() 26 | else: 27 | sb.dining_room.lights.red.on() 28 | sb.dining_room.lights.green.off() 29 | 30 | if bedroom.motion_detected: 31 | sb.bedroom.lights.green.on() 32 | sb.bedroom.lights.red.off() 33 | else: 34 | sb.bedroom.lights.red.on() 35 | sb.bedroom.lights.green.off() 36 | 37 | sleep(5) 38 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # GPIO Zero tutorial and examples for the STATUS Board and STATUS Zero 2 | 3 | [STATUS Zero](https://thepihut.com/collections/status-boards/products/status-board-zero) 4 | comprises three strips, each containing a pair of LEDS (red and green). 5 | 6 | ![STATUS Zero](images/status-zero.jpg) 7 | 8 | [STATUS Board](https://thepihut.com/collections/status-boards/products/status-board-pro) 9 | comprises five strips, each containing a button and a pair of LEDS (red and 10 | green). 11 | 12 | ![STATUS Board](images/status-board.jpg) 13 | 14 | ## Install the software 15 | 16 | To use the STATUS boards, you'll need the latest version of GPIO Zero (v1.4 or 17 | above). Simply update your package list and install or upgrade GPIO Zero with: 18 | 19 | ```bash 20 | sudo apt update 21 | sudo apt install python3-gpiozero python-gpiozero -y 22 | ``` 23 | 24 | ## Tutorials 25 | 26 | - [STATUS Zero](tutorials/status-zero/README.md) 27 | - [STATUS Board](tutorials/status-board/README.md) 28 | 29 | ## Examples 30 | 31 | - [Button demo](examples/button-demo/README.md) 32 | - [Who's in?](examples/whos-in/README.md) 33 | - [London Tube line status](examples/tube/README.md) 34 | - [Rain in cities](examples/rain/README.md) 35 | - [Websites up or down](examples/website-monitor/README.md) 36 | - [Travis build status](examples/travis-build/README.md) 37 | - [In the news](examples/news/README.md) 38 | - [Multi-room motion sensor](examples/multi-room-motion/README.md) 39 | - [Speedtest monitor](examples/speedtest/README.md) 40 | 41 | ## API documentation 42 | 43 | - [Status Zero](http://gpiozero.readthedocs.io/en/stable/api_boards.html#statuszero) 44 | - [Status Board](http://gpiozero.readthedocs.io/en/stable/api_boards.html#statusboard) 45 | -------------------------------------------------------------------------------- /examples/tube/sz_tube_simple.py: -------------------------------------------------------------------------------- 1 | from tubestatus import Status 2 | from gpiozero import StatusZero 3 | from time import sleep 4 | 5 | tube = Status() 6 | 7 | sz = StatusZero('central', 'northern', 'piccadilly') 8 | 9 | while True: 10 | central = tube.get_status('Central') 11 | sz.central.off() 12 | if central.description == 'Good Service': 13 | sz.central.green.on() 14 | elif central.description == 'Minor Delays': 15 | sz.central.green.blink() 16 | elif central.description == 'Severe Delays': 17 | sz.central.red.on() 18 | elif central.description == 'Part Closure': 19 | sz.central.red.blink() 20 | elif central.description == 'Service Closed': 21 | sz.central.off() 22 | 23 | northern = tube.get_status('Northern') 24 | sz.northern.off() 25 | if northern.description == 'Good Service': 26 | sz.northern.green.on() 27 | elif northern.description == 'Minor Delays': 28 | sz.northern.green.blink() 29 | elif northern.description == 'Severe Delays': 30 | sz.northern.red.on() 31 | elif northern.description == 'Part Closure': 32 | sz.northern.red.blink() 33 | elif northern.description == 'Service Closed': 34 | sz.northern.off() 35 | 36 | piccadilly = tube.get_status('Piccadilly') 37 | sz.piccadilly.off() 38 | if piccadilly.description == 'Good Service': 39 | sz.piccadilly.green.on() 40 | elif piccadilly.description == 'Minor Delays': 41 | sz.piccadilly.green.blink() 42 | elif piccadilly.description == 'Severe Delays': 43 | sz.piccadilly.red.on() 44 | elif piccadilly.description == 'Part Closure': 45 | sz.piccadilly.red.blink() 46 | elif piccadilly.description == 'Service Closed': 47 | sz.piccadilly.off() 48 | sleep(60) # check every minute 49 | -------------------------------------------------------------------------------- /examples/tube/sb_tube_simple.py: -------------------------------------------------------------------------------- 1 | from tubestatus import Status 2 | from gpiozero import StatusBoard 3 | from time import sleep 4 | 5 | tube = Status() 6 | 7 | sb = StatusBoard('central', 'northern', 'piccadilly') 8 | 9 | while True: 10 | central = tube.get_status('Central') 11 | sb.central.lights.off() 12 | if central.description == 'Good Service': 13 | sb.central.lights.green.on() 14 | elif central.description == 'Minor Delays': 15 | sb.central.lights.green.blink() 16 | elif central.description == 'Severe Delays': 17 | sb.central.lights.red.on() 18 | elif central.description == 'Part Closure': 19 | sb.central.lights.red.blink() 20 | elif central.description == 'Service Closed': 21 | sb.central.lights.off() 22 | 23 | northern = tube.get_status('Northern') 24 | sb.northern.lights.off() 25 | if northern.description == 'Good Service': 26 | sb.northern.lights.green.on() 27 | elif northern.description == 'Minor Delays': 28 | sb.northern.lights.green.blink() 29 | elif northern.description == 'Severe Delays': 30 | sb.northern.lights.red.on() 31 | elif northern.description == 'Part Closure': 32 | sb.northern.lights.red.blink() 33 | elif northern.description == 'Service Closed': 34 | sb.northern.lights.off() 35 | 36 | piccadilly = tube.get_status('Piccadilly') 37 | sb.piccadilly.lights.off() 38 | if piccadilly.description == 'Good Service': 39 | sb.piccadilly.lights.green.on() 40 | elif piccadilly.description == 'Minor Delays': 41 | sb.piccadilly.lights.green.blink() 42 | elif piccadilly.description == 'Severe Delays': 43 | sb.piccadilly.lights.red.on() 44 | elif piccadilly.description == 'Part Closure': 45 | sb.piccadilly.lights.red.blink() 46 | elif piccadilly.description == 'Service Closed': 47 | sb.piccadilly.lights.off() 48 | sleep(60) # check every minute 49 | -------------------------------------------------------------------------------- /tutorials/status-zero/README.md: -------------------------------------------------------------------------------- 1 | # STATUS Zero tutorial 2 | 3 | STATUS Zero comprises three strips, each containing a pair of LEDS (red and 4 | green). 5 | 6 | ## Basic usage 7 | 8 | You can control the LEDs on the board individually, in pairs, or all together: 9 | 10 | ```python 11 | from gpiozero import StatusZero 12 | from time import sleep 13 | 14 | sz = StatusZero() 15 | 16 | sz.on() # all leds on 17 | sleep(1) 18 | sz.off() # all leds off 19 | sleep(1) 20 | sz.one.on() # both leds of first strip on 21 | sleep(1) 22 | sz.two.green.on() # green led of second strip on 23 | sleep(1) 24 | sz.two.red.blink() # blink red led of second strip 25 | ``` 26 | 27 | ### PWM (variable brightness) 28 | 29 | As well as on/off you can use PWM (pulse-width modulation) to control the 30 | brightness of the LEDs: 31 | 32 | ```python 33 | from gpiozero import StatusZero 34 | from time import sleep 35 | 36 | sz = StatusZero(pwm=True) 37 | 38 | sz.on() # all leds on 39 | sleep(1) 40 | sz.off() # all leds off 41 | sleep(1) 42 | sz.one.green.value = 0.5 # green led of first strip at half brightness 43 | sleep(1) 44 | sz.two.value = (0.5, 0.5) # both leds of second strip at half brightness 45 | sleep(1) 46 | sz.one.pulse() # both leds of first strip fading in and out 47 | sleep(1) 48 | sz.two.pulse() # both leds of second strip pulsing in opposite timing with the first 49 | ``` 50 | 51 | ## Naming strips 52 | 53 | If you initialise `StatusZero` with no positional arguments, the three strips 54 | will be named `one` to `three`. Optionally, you can instead name up to three 55 | strips like so: 56 | 57 | ```python 58 | from gpiozero import StatusZero 59 | from time import sleep 60 | 61 | sz = StatusZero('a', 'b') # only using two strips 62 | 63 | sz.on() # all leds on 64 | sleep(1) 65 | sz.off() # all leds off 66 | sleep(1) 67 | sz.a.on() # both leds of first strip on 68 | sleep(1) 69 | sz.b.green.on() # green led of second strip 70 | sleep(1) 71 | ``` 72 | 73 | So if the strips represent different people, you might name the strips for each 74 | person: 75 | 76 | ```python 77 | sz = StatusZero('mum', 'dad', 'alice') 78 | ``` 79 | 80 | Or if they're monitoring whether it's raining in different cities: 81 | 82 | ```python 83 | sz = StatusZero('sheffield', 'nottingham', 'cambridge') 84 | ``` 85 | 86 | You can name up to three strips. Any without names are not used (except when 87 | none are named). 88 | 89 | ## Test the LEDs 90 | 91 | A simple example to check all your LEDs are working. Try opening a Python shell 92 | and typing these commands (you don't need to type the # comments): 93 | 94 | ```python 95 | >>> from gpiozero import StatusZero 96 | >>> sz = StatusZero() 97 | >>> sz.on() # all lights should come on 98 | >>> sz.off() ## all lights should go off 99 | >>> sz.one.on() # both lights on the first strip should come on 100 | >>> sz.two.green.on() # the green light on the second strip should come on 101 | >>> sz.two.red.on() # the red light on the second strip should come on 102 | >>> sz.three.blink() # both lights on the third strip should blink 103 | ``` 104 | 105 | ## Project 106 | 107 | The project: use two strips of the Status Zero to indicate the status of the 108 | local network, and of the internet connection. Green means online and red means 109 | offline. 110 | 111 | The `PingServer` class from GPIO Zero provides a familiar interface to checking 112 | network connections. You can use it to check whether an IP address on your local 113 | network is reachable or check your connection to the internet. 114 | 115 | Try using `PingServer` on its own in a Python shell: 116 | 117 | ```python 118 | >>> from gpiozero import PingServer 119 | >>> google = PingServer('google.com') 120 | >>> google.is_active # should print True if you are online 121 | ``` 122 | 123 | Now open a new file and type the following script: 124 | 125 | ```python 126 | from gpiozero import PingServer, StatusZero 127 | from time import sleep 128 | 129 | google = PingServer('google.com') 130 | sb = StatusZero('google') 131 | 132 | while True: 133 | if google.is_active: 134 | sb.google.green.on() 135 | sb.google.red.off() 136 | else: 137 | sb.google.green.off() 138 | sb.google.red.on() 139 | sleep(60) 140 | ``` 141 | 142 | Here we use a `while` loop to keep checking the status of the `google.com` ping 143 | every 60 seconds. If it's active, we turn the green LED on and the red off. If 144 | it's inactive, we turn the green off and the red on. 145 | 146 | If you wanted to monitor a second server alongside this, you could just add in 147 | another `PingServer` instance and add the same logic into the `while` loop. 148 | You'd also add a second named strip to the `StatusBoard`. For example if 149 | `192.168.1.1` is the IP address of your home router, you could ping it to see if 150 | your local network is reachable: 151 | 152 | ```python 153 | from gpiozero import PingServer, StatusZero 154 | from time import sleep 155 | 156 | router = PingServer('192.168.1.1') 157 | google = PingServer('google.com') 158 | 159 | sz = StatusZero('router', 'google') 160 | 161 | while True: 162 | if router.is_active: 163 | sz.router.green.on() 164 | sz.router.red.off() 165 | else: 166 | sz.router.green.off() 167 | sz.router.red.on() 168 | if google.is_active: 169 | sz.google.green.on() 170 | sz.google.red.off() 171 | else: 172 | sz.google.green.off() 173 | sz.google.red.on() 174 | sleep(60) 175 | ``` 176 | 177 | Another way of controlling the LEDs is by setting the value of a LED strip. Each 178 | LED strip's value is a 2-tuple, e.g. `(True, True)` when they're both on. `0` 179 | and `1` work as values too. 180 | 181 | ```python 182 | from gpiozero import PingServer, StatusZero 183 | from time import sleep 184 | 185 | router = PingServer('192.168.1.1') 186 | google = PingServer('google.com') 187 | 188 | sz = StatusZero('router', 'google') 189 | 190 | while True: 191 | if router.is_active: 192 | sz.router.value = (0, 1) 193 | else: 194 | sz.router.value = (1, 0) 195 | if google.is_active: 196 | sz.google.value = (0, 1) 197 | else: 198 | sz.google.value = (1, 0) 199 | sleep(60) 200 | ``` 201 | 202 | This example uses the same while loop but rather than individually turning each 203 | LED on and off, the board's value is set to `(1, 0)` (red on, green off) or 204 | `(0, 1)` (red off, green on) which is more concise and uses fewer lines of code. 205 | 206 | Rather than use a while loop to continuously set a device's value, you can use a 207 | more advanced approach, connecting an LED with a stream of values. 208 | 209 | ```python 210 | from gpiozero import PingServer, StatusZero 211 | from gpiozero.tools import negated 212 | from signal import pause 213 | 214 | sz = StatusZero('router', 'google') 215 | 216 | router = PingServer('192.168.1.1') 217 | google = PingServer('google.com') 218 | 219 | sz.router.green.source = router.values 220 | sz.router.green.source_delay = 60 221 | sz.router.red.source = negated(sz.router.green.values) 222 | 223 | sz.google.green.source = google.values 224 | sz.google.green.source_delay = 60 225 | sz.google.red.source = negated(sz.google.green.values) 226 | 227 | pause() 228 | ``` 229 | 230 | Instead of a while loop, the status of the green LED is set to follow the status 231 | of the ping server, and the red LED is set to be the opposite of the green LED. 232 | No loop is needed as this happens in the background, but `pause()` is required 233 | to keep the script running. 234 | 235 | Rather than repeating the code which sets up the green and red LEDs for each 236 | indicator, a dictionary is formed mapping each ping server to a status strip and 237 | the LED behaviour setup is in a loop. 238 | 239 | ```python 240 | from gpiozero import PingServer, StatusZero 241 | from gpiozero.tools import negated 242 | from signal import pause 243 | 244 | sz = StatusZero('router', 'google') 245 | 246 | statuses = { 247 | sz.router: PingServer('192.168.1.1'), 248 | sz.google: PingServer('google.com'), 249 | } 250 | 251 | for strip, server in statuses.items(): 252 | strip.green.source = server.values 253 | strip.green.source_delay = 60 254 | strip.red.source = negated(strip.green.values) 255 | 256 | pause() 257 | ``` 258 | 259 | ## More 260 | 261 | You can use almost anything as the "input" for your STATUS indicator. If it's 262 | another GPIO Zero device, like a sensor or one of the internal devices like 263 | above, that's easy because they're made to be connected up. If it's something 264 | else entirely, all you have to do is write a function which calculates a True or 265 | False value to send to the LEDs. 266 | 267 | For example, use `requests` to get the content from the BBC News homepage, and 268 | check to see if the text contains any particular names (in case you want to 269 | avoid it!): 270 | 271 | ```python 272 | def in_the_news(text): 273 | url = 'http://www.bbc.co.uk/news' 274 | r = requests.get(url) 275 | return text in r.text 276 | ``` 277 | 278 | This function returns `True` if the term passed in can be found in the web 279 | request, and `False` if not. Therefore `if in_the_news('Donald Trump')` would 280 | pass if Donald Trump was in the news, and would go to the `else` if not. 281 | 282 | The example in full: 283 | 284 | ```python 285 | from gpiozero import StatusZero 286 | import requests 287 | from time import sleep 288 | 289 | def in_the_news(text): 290 | url = 'http://www.bbc.co.uk/news' 291 | r = requests.get(url) 292 | return text in r.text 293 | 294 | sz = StatusZero() 295 | 296 | while True: 297 | if in_the_news('Donald Trump'): 298 | sz.one.red.on() 299 | sz.one.green.off() 300 | else: 301 | sz.one.green.on() 302 | sz.one.red.on() 303 | sleep(60*60) # check every hour 304 | 305 | ``` 306 | 307 | Alternatively, using the source/values technique, the function would contain a 308 | `while True` and would `yield` the value each time, checking at an interval 309 | determined by the `source_delay`. 310 | 311 | ```python 312 | def in_the_news(text): 313 | url = 'http://www.bbc.co.uk/news' 314 | while True: 315 | r = requests.get(url) 316 | yield text in r.text 317 | ``` 318 | 319 | And in full: 320 | 321 | ```python 322 | from gpiozero import StatusZero 323 | from gpiozero.tools import negated 324 | import requests 325 | from signal import pause 326 | 327 | def in_the_news(text): 328 | url = 'http://www.bbc.co.uk/news' 329 | while True: 330 | r = requests.get(url) 331 | yield text in r.text 332 | 333 | sz = StatusZero() 334 | 335 | sz.one.red.source = in_the_news('Donald Trump') 336 | sz.one.red.source_delay = 60 # check every hour 337 | sz.one.green.source = negated(sz.one.red.values) 338 | 339 | pause() 340 | ``` 341 | 342 | ## Examples 343 | 344 | Next, check out some [examples](../../examples/README.md) 345 | -------------------------------------------------------------------------------- /tutorials/status-board/README.md: -------------------------------------------------------------------------------- 1 | # STATUS Board tutorial 2 | 3 | STATUS Board comprises five strips, each containing a button (available separately) and a pair of LEDS 4 | (red and green). 5 | 6 | ## Basic usage 7 | 8 | You can control the LEDs on the board individually, in pairs, or all together. 9 | You can also wait for button presses or fire events when buttons are pressed. 10 | 11 | ```python 12 | from gpiozero import StatusBoard 13 | from time import sleep 14 | 15 | sb = StatusBoard() 16 | 17 | sb.one.button.wait_for_press() # wait for the first button to be pressed 18 | sb.on() # all leds on 19 | sb.one.button.wait_for_release() # wait for the first button to be released 20 | sleep(1) 21 | sb.off() # all leds off 22 | sleep(1) 23 | sb.one.on() # both leds of first strip on 24 | sleep(1) 25 | sb.two.lights.green.on() # green led of second strip on 26 | sleep(1) 27 | sb.two.lights.red.blink() # blink red led of second strip 28 | ``` 29 | 30 | ### PWM (variable brightness) 31 | 32 | As well as on/off you can use PWM (pulse-width modulation) to control the 33 | brightness of the LEDs: 34 | 35 | ```python 36 | from gpiozero import StatusBoard 37 | from time import sleep 38 | 39 | sb = StatusBoard(pwm=True) 40 | 41 | sb.on() # all leds on 42 | sleep(1) 43 | sb.off() # all leds off 44 | sleep(1) 45 | sb.one.lights.green.value = 0.5 # green led of first strip at half brightness 46 | sleep(1) 47 | sb.two.lights.value = (0.5, 0.5) # both leds of second strip at half brightness 48 | sleep(1) 49 | sb.one.lights.pulse() # both leds of first strip fading in and out 50 | sleep(1) 51 | sb.two.lights.pulse() # both leds of second strip pulsing in opposite timing with the first 52 | ``` 53 | 54 | ## Naming strips 55 | 56 | If you initialise `StatusBoard` with no positional arguments, the five strips 57 | will be named `one` to `five`. Optionally, you can instead name up to five 58 | strips like so: 59 | 60 | ```python 61 | from gpiozero import StatusBoard 62 | from time import sleep 63 | 64 | sb = StatusBoard('a', 'b', 'c', 'd') # only using four strips 65 | 66 | sb.on() # all leds on 67 | sleep(1) 68 | sb.off() # all leds off 69 | sleep(1) 70 | sb.a.on() # both leds of first strip on 71 | sleep(1) 72 | sb.d.lights.green.on() # green led of fourth strip on 73 | sleep(1) 74 | ``` 75 | 76 | So if the strips represent different people, you might name the strips for each 77 | person: 78 | 79 | ```python 80 | sb = StatusBoard('mum', 'dad', 'alice', 'bob') 81 | ``` 82 | 83 | Or if they're monitoring whether it's raining in different cities: 84 | 85 | ```python 86 | sb = StatusBoard('sheffield', 'nottingham', 'cambridge', 'dundee') 87 | ``` 88 | 89 | You can name up to five strips. Any without names are not used (except when none 90 | are named). 91 | 92 | ## Test the LEDs 93 | 94 | A simple example to check all your LEDs are working. Try opening a Python shell 95 | and typing these commands (you don't need to type the # comments): 96 | 97 | ```python 98 | >>> from gpiozero import StatusBoard 99 | >>> sb = StatusBoard() 100 | >>> sb.one.lights.on() # both lights on the first strip should come on 101 | >>> sb.two.lights.green.on() # the green light on the second strip should come on 102 | >>> sb.two.lights.red.on() # the red light on the second strip should come on 103 | >>> sb.three.lights.blink() # both lights on the third strip should blink 104 | >>> for strip in sb: 105 | ... strip.lights.on() # all lights should come on 106 | ``` 107 | 108 | ## Test the buttons 109 | 110 | A simple example to check all your buttons are working: 111 | 112 | ```python 113 | >>> from gpiozero import StatusBoard 114 | >>> sb = StatusBoard() 115 | >>> for n, strip in enumerate(sb, 1): 116 | ... strip.button.when_pressed = lambda: print('button {} pressed'.format(n)) 117 | ``` 118 | 119 | A simple example to test toggling the lights when buttons are pressed: 120 | 121 | ```python 122 | >>> from gpiozero import StatusBoard 123 | >>> sb = StatusBoard() 124 | >>> for n, strip in sb: 125 | ... strip.lights.red.on() 126 | ... strip.button.when_pressed = strip.lights.toggle 127 | ``` 128 | 129 | ## Project 130 | 131 | The project: use two strips of the Status Board to indicate the status of the 132 | local network, and of the internet connection. Green means online and red means 133 | offline. 134 | 135 | The `PingServer` class from GPIO Zero provides a familiar interface to checking 136 | network connections. You can use it to check whether an IP address on your local 137 | network is reachable or check your connection to the internet. 138 | 139 | Try using `PingServer` on its own in a Python shell: 140 | 141 | ```python 142 | >>> from gpiozero import PingServer 143 | >>> google = PingServer('google.com') 144 | >>> google.is_active # should print True if you are online 145 | ``` 146 | 147 | Now open a new file and type the following script: 148 | 149 | ```python 150 | from gpiozero import PingServer, StatusBoard 151 | from time import sleep 152 | 153 | google = PingServer('google.com') 154 | sb = StatusBoard('google') 155 | 156 | while True: 157 | if google.is_active: 158 | sb.google.lights.green.on() 159 | sb.google.lights.red.off() 160 | else: 161 | sb.google.lights.green.off() 162 | sb.google.lights.red.on() 163 | sleep(60) 164 | ``` 165 | 166 | Here we use a `while` loop to keep checking the status of the `google.com` ping 167 | every 60 seconds. If it's active, we turn the green LED on and the red off. If 168 | it's inactive, we turn the green off and the red on. 169 | 170 | If you wanted to monitor a second server alongside this, you could just add in 171 | another `PingServer` instance and add the same logic into the `while` loop. 172 | You'd also add a second named strip to the `StatusBoard`. For example if 173 | `192.168.1.1` is the IP address of your home router, you could ping it to see if 174 | your local network is reachable: 175 | 176 | ```python 177 | from gpiozero import PingServer, StatusBoard 178 | from time import sleep 179 | 180 | router = PingServer('192.168.1.1') 181 | google = PingServer('google.com') 182 | 183 | sb = StatusBoard('router', 'google') 184 | 185 | while True: 186 | if router.is_active: 187 | sb.router.lights.green.on() 188 | sb.router.lights.red.off() 189 | else: 190 | sb.router.lights.green.off() 191 | sb.router.lights.red.on() 192 | if google.is_active: 193 | sb.google.lights.green.on() 194 | sb.google.lights.red.off() 195 | else: 196 | sb.google.lights.green.off() 197 | sb.google.lights.red.on() 198 | sleep(60) 199 | ``` 200 | 201 | Another way of controlling the LEDs is by setting the value of a LED strip. Each 202 | LED strip's value is a 2-tuple, e.g. `(True, True)` when they're both on. `0` 203 | and `1` work as values too. 204 | 205 | ```python 206 | from gpiozero import PingServer, StatusBoard 207 | from time import sleep 208 | 209 | router = PingServer('192.168.1.1') 210 | google = PingServer('google.com') 211 | 212 | sb = StatusBoard('router', 'google') 213 | 214 | while True: 215 | if router.is_active: 216 | sb.router.lights.value = (0, 1) 217 | else: 218 | sb.router.lights.value = (1, 0) 219 | if google.is_active: 220 | sb.google.lights.value = (0, 1) 221 | else: 222 | sb.google.lights.value = (1, 0) 223 | sleep(60) 224 | ``` 225 | 226 | This example uses the same while loop but rather than individually turning each 227 | LED on and off, the board's value is set to `(1, 0)` (red on, green off) or 228 | `(0, 1)` (red off, green on) which is more concise and uses fewer lines of code. 229 | 230 | Rather than use a while loop to continuously set a device's value, you can use a 231 | more advanced approach, connecting an LED with a stream of values. 232 | 233 | ```python 234 | from gpiozero import PingServer, StatusBoard 235 | from signal import pause 236 | 237 | sb = StatusBoard('router', 'google') 238 | 239 | router = PingServer('192.168.1.1') 240 | google = PingServer('google.com') 241 | 242 | sb.router.lights.green.source = router.values 243 | sb.router.lights.green.source_delay = 60 244 | sb.router.lights.red.source = negated(sb.router.lights.green.values) 245 | 246 | sb.google.lights.green.source = google.values 247 | sb.google.lights.green.source_delay = 60 248 | sb.google.lights.red.source = negated(sb.google.lights.green.values) 249 | 250 | pause() 251 | ``` 252 | 253 | Instead of a while loop, the status of the green LED is set to follow the status 254 | of the ping server, and the red LED is set to be the opposite of the green LED. 255 | No loop is needed as this happens in the background, but `pause()` is required 256 | to keep the script running. 257 | 258 | Rather than repeating the code which sets up the green and red LEDs for each 259 | indicator, a dictionary is formed mapping each ping server to a status strip and 260 | the LED behaviour setup is in a loop. 261 | 262 | ```python 263 | from gpiozero import PingServer, StatusBoard 264 | from signal import pause 265 | 266 | sb = StatusBoard('router', 'google') 267 | 268 | statuses = { 269 | sb.router: PingServer('192.168.1.1'), 270 | sb.google: PingServer('google.com'), 271 | } 272 | 273 | for server, strip in statuses.items(): 274 | strip.lights.green.source = server.values 275 | strip.lights.green.source_delay = 60 276 | strip.lights.red.source = negated(strip.lights.green.values) 277 | 278 | pause() 279 | ``` 280 | 281 | ## More 282 | 283 | You can use almost anything as the "input" for your STATUS indicator. If it's 284 | another GPIO Zero device, like a sensor or one of the internal devices like 285 | above, that's easy because they're made to be connected up. If it's something 286 | else entirely, all you have to do is write a function which calculates a True or 287 | False value to send to the LEDs. 288 | 289 | For example, use `requests` to get the content from the BBC News homepage, and 290 | check to see if the text contains any particular names (in case you want to 291 | avoid it!): 292 | 293 | ```python 294 | def in_the_news(text): 295 | url = 'http://www.bbc.co.uk/news' 296 | r = requests.get(url) 297 | return text in r.text 298 | ``` 299 | 300 | This function returns `True` if the term passed in can be found in the web 301 | request, and `False` if not. Therefore `if in_the_news('Donald Trump')` would 302 | pass if Donald Trump was in the news, and would go to the `else` if not. 303 | 304 | The example in full: 305 | 306 | ```python 307 | from gpiozero import StatusBoard 308 | import requests 309 | from time import sleep 310 | 311 | def in_the_news(text): 312 | url = 'http://www.bbc.co.uk/news' 313 | r = requests.get(url) 314 | return text in r.text 315 | 316 | sb = StatusBoard() 317 | 318 | while True: 319 | if in_the_news('Donald Trump'): 320 | sb.one.lights.red.on() 321 | sb.one.lights.green.off() 322 | else: 323 | sb.one.lights.green.on() 324 | sb.one.lights.red.on() 325 | sleep(60*60) # check every hour 326 | 327 | ``` 328 | 329 | Alternatively, using the source/values technique, the function would contain a 330 | `while True` and would `yield` the value each time, checking at an interval 331 | determined by the `source_delay`. 332 | 333 | ```python 334 | def in_the_news(text): 335 | url = 'http://www.bbc.co.uk/news' 336 | while True: 337 | r = requests.get(url) 338 | yield text in r.text 339 | ``` 340 | 341 | And in full: 342 | 343 | ```python 344 | from gpiozero import StatusBoard 345 | from gpiozero.tools import negated 346 | import requests 347 | from signal import pause 348 | 349 | def in_the_news(text): 350 | url = 'http://www.bbc.co.uk/news' 351 | while True: 352 | r = requests.get(url) 353 | yield text in r.text 354 | 355 | sb = StatusBoard() 356 | 357 | sb.one.lights.red.source = in_the_news('Donald Trump') 358 | sb.one.lights.red.source_delay = 60 # check every hour 359 | sb.one.lights.green.source = negated(sb.one.lights.red.values) 360 | 361 | pause() 362 | ``` 363 | 364 | ## Use button for update 365 | 366 | One use of the buttons could be to prompt the status lights to update: 367 | 368 | ```python 369 | from gpiozero import PingServer, StatusBoard 370 | from signal import pause 371 | 372 | sb = StatusBoard('google') 373 | 374 | google = PingServer('google.com') 375 | 376 | def update(): 377 | if google.is_active: 378 | sb.google.lights.green.on() 379 | sb.google.lights.red.off() 380 | else: 381 | sb.google.lights.red.on() 382 | sb.google.lights.green.off() 383 | 384 | sb.google.button.when_pressed = update 385 | 386 | pause() 387 | ``` 388 | 389 | And to have it auto-update every minute, but also when pressed: 390 | 391 | ```python 392 | from gpiozero import PingServer, StatusBoard 393 | from time import sleep 394 | 395 | sb = StatusBoard('google') 396 | 397 | google = PingServer('google.com') 398 | 399 | def update(): 400 | if google.is_active: 401 | sb.google.lights.green.on() 402 | sb.google.lights.red.off() 403 | else: 404 | sb.google.lights.red.on() 405 | sb.google.lights.green.off() 406 | 407 | sb.google.button.when_pressed = update 408 | 409 | while True: 410 | update() 411 | ``` 412 | 413 | or using the source/values approach: 414 | 415 | ```python 416 | from gpiozero import PingServer, StatusBoard 417 | from signal import pause 418 | 419 | sb = StatusBoard('google') 420 | 421 | google = PingServer('google.com') 422 | 423 | def update(): 424 | sb.google.lights.green.value = google.value 425 | 426 | sb.google.lights.green.source = google.values 427 | sb.google.lights.green.source_delay = 60 428 | sb.google.lights.red.source = negated(sb.google.lights.green.values) 429 | sb.google.button.when_pressed = update 430 | 431 | pause() 432 | ``` 433 | 434 | ## Examples 435 | 436 | Next, check out some [examples](../../examples/README.md) 437 | --------------------------------------------------------------------------------