diff --git a/README.md b/README.md index 6e00421..c851cb5 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,9 @@ sudo apt-get install python-imaging git submodule update --init cd rpi-rgb-led-matrix/ make +cp rgbmatrix.so ../ sudo ./minimal-example sudo ./led-matrix -D 0 sudo python matrixtest.py -``` \ No newline at end of file +``` + diff --git a/images/100px-LightOff.svg.png b/images/32px-LightOff.svg.png similarity index 100% rename from images/100px-LightOff.svg.png rename to images/32px-LightOff.svg.png diff --git a/images/100px-LightOn.svg.png b/images/32px-LightOn.svg.png similarity index 100% rename from images/100px-LightOn.svg.png rename to images/32px-LightOn.svg.png diff --git a/main.py b/main.py index 3f183ad..837603e 100755 --- a/main.py +++ b/main.py @@ -4,16 +4,49 @@ import Image import ImageDraw import time +from rgbmatrix import Adafruit_RGBmatrix + import requests import json +# Rows and chain length are both required parameters: +matrix = Adafruit_RGBmatrix(32, 3) + r = requests.get('https://spaceapi.syn2cat.lu/status/json') obj = json.loads(r.text) -presence = obj["sensors"]["people_now_present"][0]["value"] +def main(): + + presence = obj["sensors"]["people_now_present"][0]["value"] -if obj["state"]["open"]: - print("And we are open!") - print("There are {} Hackers present NOW!".format(presence)) + if obj["state"]["open"]: + print("And we are open!") + print("There are {} Hackers present NOW!".format(presence)) + openSpace() + + if obj["state"]["closed"]: + print("And we are closed!") + print("There were {} Hackers present! Good night, good fight!".format(presence)) + closedSpace() + + +def openSpace(): + matrix.Clear() + image = Image.open("images/32px-LightOn.svg.png") + image.load() + for n in range(32, -image.size[0], -1): + matrix.SetImage(image.im.id, n, 1) + time.sleep(0.025) + +def closedSpace(): + matrix.Clear() + image = Image.open("images/32px-LightOf.svg.png") + image.load() + for n in range(32, -image.size[0], -1): + matrix.SetImage(image.im.id, n, 1) + time.sleep(0.025) + + +if __name__ == “__main__”: main()