Skip to content

Instantly share code, notes, and snippets.

View martinohanlon's full-sized avatar

Martin O'Hanlon martinohanlon

View GitHub Profile
@martinohanlon
martinohanlon / demo.py
Last active September 23, 2020 10:21
DM@H paint app
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 July 14, 2020 08:08
A utility for padding image files.
"""
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):
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']
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']
@martinohanlon
martinohanlon / sensehat_tilt.py
Created April 18, 2019 13:18
Sense HAT tilting
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 December 30, 2018 22:23
A remote controlled light using Blue Dot and a pimoroni blinkt.
# 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 August 29, 2022 20:53
a guizero app which uses the picamera to make stop motion gifs
# 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 June 15, 2018 15:26
A push button animation with guizero
# 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 June 13, 2018 15:36
guizero character counting example
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 June 28, 2022 08:29
picamera motion detection - super hacky!
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)