Skip to content

Instantly share code, notes, and snippets.

@dlech
dlech / main.py
Created April 14, 2024 21:42
Resolver test bench
#!/usr/bin/env pybricks-micropython
# SPDX-License-Identifier: MIT
# Copyright (c) 2024 David Lechner <dlechner@baylibre.com>
import math
from pybricks.hubs import EV3Brick
from pybricks.ev3devices import Motor, InfraredSensor
from pybricks.parameters import Port, Direction, Button
from pybricks.tools import wait
@dlech
dlech / robot_arm_h25.py
Created January 30, 2016 04:40
ev3dev-lang-python program for the Robot Arm H25 model that is part of the 45544 LEGO Education EV3 kit.
#!/usr/bin/env python
#
# ev3dev-lang-python program for the Robot Arm H25 model that is part of
# the 45544 LEGO Education EV3 kit.
#
# Authors:
# David Lechner <david@lechnology.com>
#
from ev3dev.ev3 import *
@dlech
dlech / gelo.py
Last active September 19, 2023 07:40
A program for LEGO MINDSTORMS Robot Inventor - Gelo model
# SPDX-License-Identifier: MIT
# Copyright (c) 2021 David Lechner <david@pybricks.com>
# A program for LEGO MINDSTORMS Robot Inventor - Gelo
# Developed using MINDSTORMS App v1.3.4 (10.1.0), hub firmware v1.2.01.0103
# Building instructions: https://www.lego.com/cdn/product-assets/product.bi.additional.main.pdf/51515_Gelo.pdf
# Hub API: https://lego.github.io/MINDSTORMS-Robot-Inventor-hub-API/
@dlech
dlech / fullscreen.js
Last active July 26, 2023 17:13
Pybricks Code Full Screen Editor TamperMonkey Script
// ==UserScript==
// @name Pybricks Code Full Screen Editor
// @namespace https://pybricks.com/tampermonkey/full-screen-editor
// @version 1.0.0
// @description Full screen text editor for Pybricks Code.
// @author David Lechner
// @match https://code.pybricks.com
// @match https://beta.pybricks.com
// @icon https://pybricks.com/favion.ico
// @grant none
@dlech
dlech / multitask.py
Last active March 28, 2023 14:09
Example of LEGO SPIKE Prime scratch program translated to MicroPython using generator functions as coroutines
# spike.control.wait_for_seconds doesn't allow decimal points
# so we replace it with the standard MicroPython sleep function instead
from utime import sleep as wait_for_seconds
from utime import ticks_diff, ticks_ms
# See https://docs.micropython.org/en/latest/library/utime.html for more info on the utime module
from spike import (PrimeHub, LightMatrix, Button, StatusLight, ForceSensor, MotionSensor,
Speaker, ColorSensor, App, DistanceSensor, Motor, MotorPair)
from spike.control import wait_until
@dlech
dlech / square-names.js
Last active February 8, 2023 22:17
Chess.com square names
// ==UserScript==
// @name Square names
// @source https://gist.github.com/dlech/2e0e9304458b9f7b816a59e3f187a04b
// @namespace com.lechnology.chess.squares
// @version 1.0.0
// @description Display the square names on each square.
// @author David Lechner
// @match https://www.chess.com/*
// @grant none
// ==/UserScript==
@dlech
dlech / gyroboy.py
Last active November 11, 2022 18:32
#!/usr/bin/env python3
#
# gyroboy.py - translation of the LEGO Education GyroBoy program to python for ev3dev
#
# MIT License
#
# Copyright (c) 2016 David Lechner <david@lechnology.com>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
@dlech
dlech / htway.py
Last active October 11, 2022 15:26
ev3dev HTWay
#!/usr/bin/env python
# Python port of the HiTechnic HTWay for ev3dev
# Copyright (c) 2014-2015 G33kDude, David Lechner
# HiTechnic HTWay is Copyright (c) 2010 HiTechnic
import itertools
import os
import struct
import smbus
import time
for bus in range(3, 7):
try:
i2c = smbus.SMBus(bus)
print "Input port %d:" % (bus - 2)
for addr in range(0x01, 0x80, 2):
try:
for offset in range(0, 24, 8):
@dlech
dlech / spike-prime-large-drive-base-remote.py
Last active June 2, 2021 23:30
Example Pybricks remote control program for SPIKE Prime large drive base (experimental)
from pybricks.hubs import PrimeHub
from pybricks.experimental import Remote
from pybricks.pupdevices import Motor
from pybricks.parameters import Button, Port, Direction
from pybricks.robotics import DriveBase
from pybricks.tools import wait
DRIVE_SPEED = 400
hub = PrimeHub()