Instantly share code, notes, and snippets.

View manual_lightsensor.py
from gpiozero import InputDevice, OutputDevice
from time import time, sleep
def read_light_sensor(pin):
with OutputDevice(pin) as cap:
cap.value = 0
sleep(0.1)
# Time the charging of the capacitor
start = time()
with InputDevice(pin) as ldr:
View sensehat_scroll.md

Sense HAT scroll message

What's needed

  • Raspberry Pi with Sense HAT

The activity

The participant starts by running a pre-written script which scrolls the message "Hello world". They then change the message to one of their own, and run again. They can then change the colour. Finally they are given code with a loop showing the Raspberry Pi logo followed by the scrolling message at a different speed and in different colours, which they can play with.

View noisylightsensor.py
from gpiozero import LightSensor
from time import time, sleep
class NoisyLightSensor(LightSensor):
def _read(self):
# Drain charge from the capacitor
self.pin.function = 'output'
self.pin.state = False
sleep(0.1)
# Time the charging of the capacitor
View grpcio.sh
mapfile -t versions < versions.txt
for v in "${versions[@]}"
do
echo $v
date
/usr/bin/time -f "piw-import grpcio-$v-*.whl -y --duration 00:%E" -ao grpcio_imports.sh pip3 wheel grpcio==$v -q --no-deps --no-binary :grpcio:
done
View armv7tov6.sh
for f in *armv7l.whl;
do mv $f ${f%armv7l.whl}armv6l.whl;
done
View button.py
# run this in a console
from gpiozero import Button
from time import sleep
btn = Button(2)
def foo():
while True:
print("foo")
View README.md

Requirements:

sudo pip3 install pypollen geopy
View hands.txt
High Card: 1,302,540 (50.1177%)
Pair: 1,098,240 (42.2569%)
Two Pair: 123,552 (4.7539%)
Three of a Kind: 54,912 (2.1128%)
Straight: 10,200 (0.3925%)
Flush: 5,108 (0.1965%)
Full House: 3,744 (0.1441%)
Four of a Kind: 624 (0.0240%)
Straight Flush: 36 (0.0014%)
Royal Flush: 4 (0.0002%)
View sense_hat_emu.py
from sense_hat import SenseHat
from sense_emu import SenseHat as SenseEmu
hat = SenseHat()
emu = SenseEmu()
while True:
temp = emu.temperature
r = int(min(max(0, temp), 100) / 100 * 255)
print('{:3d}'.format(r), end='\r', flush=True)