Skip to content

Instantly share code, notes, and snippets.

Avatar

Martin O'Hanlon martinohanlon

View GitHub Profile
@martinohanlon
martinohanlon / demo.py
Last active Sep 23, 2020
DM@H paint app
View demo.py
from guizero import App, Text, Drawing, Combo, Box, Slider, PushButton
def start(event):
painting.start_event = event
def draw(event):
painting.line(
painting.start_event.x, painting.start_event.y,
event.x, event.y,
color=color_picker.value,
@martinohanlon
martinohanlon / img_pad.py
Created Jul 14, 2020
A utility for padding image files.
View img_pad.py
"""
A utility for padding image files.
"""
from PIL import Image, ImageOps, UnidentifiedImageError
import os.path
def find_files(path, file_names=[], extensions=[]):
def valid_file(file_path):
View sense_hat_shaken.py
from sense_hat import SenseHat
def display_acceleration(x, y, z):
print("{:06.2f}|{:06.2f}|{:06.2f}".format(x, y, z))
sense = SenseHat()
while True:
acceleration = sense.get_accelerometer_raw()
x = acceleration['x']
View sense_hat_move.py
from sense_hat import SenseHat
def display_acceleration(x, y, z):
print("{:06.2f}|{:06.2f}|{:06.2f}".format(x, y, z))
sense = SenseHat()
while True:
acceleration = sense.get_accelerometer_raw()
x = acceleration['x']
View sensehat_tilt.py
from sense_hat import SenseHat
sense = SenseHat()
tilt = "flat"
def display_orientation(yaw, pitch, roll, tilt):
print("{:06.2f}|{:06.2f}|{:06.2f}|{}".format(yaw, pitch, roll, tilt))
while True:
pos = sense.get_orientation()
@martinohanlon
martinohanlon / blinkt_remote.py
Created Dec 30, 2018
A remote controlled light using Blue Dot and a pimoroni blinkt.
View blinkt_remote.py
# A remote controlled light using Blue Dot and a pimoroni blinkt.
# install packages - sudo pip3 install bluedot, blinkt, colorzero
import blinkt
from bluedot import BlueDot
from signal import pause
from colorzero import Color
from threading import Event
class BlinktDot():
@martinohanlon
martinohanlon / guizero_stopmotion.py
Last active Aug 29, 2022
a guizero app which uses the picamera to make stop motion gifs
View guizero_stopmotion.py
# This is a simple gui for creating stop motion animations using the Pi camera
# martin@ohanlonweb.com
# stuffaboutcode.com
# Instructions:
# - Connect a camera module
# - Enable the camera (Menu > Preferences > Raspberry Pi Configuration, Interfaces, Camera)
# - Install the relevant modules, open a terminal (Menu > Accessories > Terminal) and run:
# - sudo pip3 install guizero
# - sudo pip3 install imageio
@martinohanlon
martinohanlon / guizero_pushbutton_animation.py
Created Jun 15, 2018
A push button animation with guizero
View guizero_pushbutton_animation.py
# Install
# - sudo pip3 install guizero
# - sudo pip3 install imageio
# - Attached a picamera and a button to pin 17
# - Run it
from guizero import App, Picture, PushButton, Text
from picamera import PiCamera
from picamera.array import PiRGBArray
from gpiozero import Button
@martinohanlon
martinohanlon / char_count.py
Created Jun 13, 2018
guizero character counting example
View char_count.py
from guizero import App, TextBox, Text
def count():
result.value = len(text_to_count.value) - 1
app = App(title="character count")
instruction = Text(app, text="Put your text here")
text_to_count = TextBox(app, multiline = True, width=60, height=25, command=count)
text_to_count.when_key_released = count
result = Text(app, text="0")
@martinohanlon
martinohanlon / detect_motion.py
Last active Jun 28, 2022
picamera motion detection - super hacky!
View detect_motion.py
from picamera import PiCamera, PiCameraCircularIO, PiVideoFrameType
from picamera.array import PiRGBArray
from time import sleep
import io
import cv2
def diff_image(t0, t1, t2):
d1 = cv2.absdiff(t2, t1)
d2 = cv2.absdiff(t1, t0)
return cv2.bitwise_and(d1, d2)