This file contains 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: |
This file contains 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
Raspberry Pi Zero #pizero | |
£4 computer made by UK educational charity given away free with MagPi magazine | |
PyGame Zero #pygamezero | |
Zero-boilerplate version of Python game programming module | |
GPIO Zero #gpiozero |
This file contains 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 InputDevice | |
NUM_PINS = 28 | |
PULL_UP_PINS = [2, 3] | |
PINS = list(set(list(range(NUM_PINS))) - set(PULL_UP_PINS)) | |
MINIMUM_DOTS_REQUIRED = 5 | |
COLOR_PINS = { | |
27: 'red', | |
10: 'green', |
This file contains 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
Verifying that +bennuttall is my blockchain ID. https://onename.com/bennuttall |
This file contains 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 gpizero import PiLiter | |
from time import sleep | |
lite = PiLiter() | |
while True: | |
lite.on() | |
sleep(1) | |
lite.off() | |
sleep(1) |
This file contains 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 TrafficLights | |
lights = TrafficLights(4, 5, 6, pwm=True) | |
def pulse(): | |
while True: | |
for i in range(10): | |
lights.green.value = i / 10 | |
sleep(0.01) | |
for i in reversed(range(10)): |
This file contains 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 | |
from time import sleep | |
from signal import pause | |
red = LED(35) | |
green = LED(47) | |
def blink(n): | |
red.blink(n, n) | |
sleep(n) |
This file contains 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
sudo apt-get install build-essential python-dev python3-dev python-virtualenv python3-virtualenv -y | |
git clone https://github.com/rpi-distro/python-gpiozero | |
virtualenv -p python3 gpiozero-env | |
source gpiozero-env/bin/activate | |
cd python-gpiozero | |
python setup.py develop | |
pip install ipython rpi.gpio |
This file contains 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
import pygame.mixer | |
from pygame.mixer import Sound | |
pygame.mixer.init() | |
sound = Sound("samples/drum_tom_mid_hard.wav") | |
sound.play() |
This file contains 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 | |
from time import sleep | |
from signal import pause | |
led1 = LED(4) | |
led2 = LED(18) | |
led1.blink(on_time=1, off_time=1) | |
sleep(1) # so they're blinking opposite | |
led2.blink(on_time=1, off_time=1) |