Last active
December 7, 2015 00:03
-
-
Save bennuttall/8aa874e8f70ca5ff9a17 to your computer and use it in GitHub Desktop.
Number of astronauts in space
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from gpiozero import LED | |
| import requests | |
| from time import sleep | |
| pins = [9, 22, 8, 18, 7, 17, 25, 23, 24] # choose your own pin numbers - these are the SnowPi pins | |
| leds = [LED(p) for p in pins] | |
| url = "http://api.open-notify.org/astros.json" | |
| while True: | |
| r = requests.get(url) | |
| j = r.json() | |
| n = j['number'] | |
| for i, led in enumerate(leds): | |
| if n > i: | |
| led.on() | |
| else: | |
| led.off() | |
| sleep(60) # update every minute |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment