Skip to content

Instantly share code, notes, and snippets.

View bennuttall's full-sized avatar

Ben Nuttall bennuttall

View GitHub Profile
@bennuttall
bennuttall / astros.py
Last active December 7, 2015 00:03
Number of astronauts in space
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:
@bennuttall
bennuttall / zero.txt
Created December 7, 2015 18:12
Zero all the things
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
@bennuttall
bennuttall / dots.py
Last active August 27, 2023 00:05
DOTS Python code
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',
Verifying that +bennuttall is my blockchain ID. https://onename.com/bennuttall
from gpizero import PiLiter
from time import sleep
lite = PiLiter()
while True:
lite.on()
sleep(1)
lite.off()
sleep(1)
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)):
@bennuttall
bennuttall / onboard_leds.py
Created February 8, 2016 23:24
Programming the onboard LEDs (activity and power lights) with GPIO Zero
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)
@bennuttall
bennuttall / gpiozero.sh
Last active September 20, 2018 11:26
virtualenv for gpiozero testing
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
@bennuttall
bennuttall / music.py
Created February 9, 2016 16:38
pygame sounds
import pygame.mixer
from pygame.mixer import Sound
pygame.mixer.init()
sound = Sound("samples/drum_tom_mid_hard.wav")
sound.play()
@bennuttall
bennuttall / led.py
Last active February 12, 2016 10:05
pwmled
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)