Skip to content

Instantly share code, notes, and snippets.

@ukBaz
ukBaz / pydbus_read_write.py
Last active Nov 1, 2021
Simple script for reading and writing BLE characteristics
View pydbus_read_write.py
"""
Simple Linux Python BLE central device communicate with micro:bit
"""
from time import sleep
import pydbus
from gi.repository import GLib
DEVICE_ADDR = 'DE:82:35:E7:CE:BE' # micro:bit address
BTN_A_STATE = 'E95DDA90-251D-470A-A062-FA1922DFA9A8'
@ukBaz
ukBaz / fibonacci.py
Last active Feb 25, 2021
Fibonacci Sequence using collections.deque
View fibonacci.py
from collections import deque
correct_values = [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610,
987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368,
75025, 121393, 196418, 317811]
def get_item(request):
fib_seq = deque([0, 1], 2)
if request < 2:
@ukBaz
ukBaz / BlueDotBlinktColorPicker.py
Created Jun 2, 2017 — forked from dglaude/BlueDotBlinktColorPicker.py
HSV color control of the Blinkt! from a Blue Dot.
View BlueDotBlinktColorPicker.py
#!/usr/bin/env python
from bluedot import BlueDot
import colorsys
import time
import blinkt
def move(pos):
# print("The Blue Dot x={} y={} d={} a={}".format(pos.x, pos.y, pos.distance, pos.angle))
h=((pos.angle+180) % 360) / 360
@ukBaz
ukBaz / big_button_gui.py
Last active Aug 26, 2019
Big Button Project Prototype
View big_button_gui.py
import logging
from gi.repository import GLib
import guizero
import big_button_project
logger = logging.getLogger('BigButton')
loop = GLib.MainLoop()
@ukBaz
ukBaz / Install Bluez Script
Created Jan 17, 2017
Instructions for installation
View Install Bluez Script
sudo apt-get install bluetooth bluez-tools
sudo apt-get install build-essential autoconf glib2.0 libglib2.0-dev libdbus-1-dev libudev-dev libical-dev libreadline-dev
sudo apt-get install rsync python-dbus python3-dbus python-dbusmock python3-dbusmock
sudo pip3 install Sphinx
sudo pip3 install sphinx_rtd_theme
sudo pip3 install pycodestyle
View connected_devices.py
#!/usr/bin/env python3
import dbus
import dbus.mainloop.glib
from gi.repository import GLib
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
mainloop = GLib.MainLoop()
def interfaces_added(path, interfaces):
View mote_remote.py
from time import sleep
from mote import Mote
from bluezero import constants
from bluezero import tools
from bluezero import adapter
from bluezero import device
from bluezero.GATT import Characteristic
display_on = False