Skip to content

Instantly share code, notes, and snippets.

View ViewController.swift
//
// ViewController.swift
// WebSocketInjection
//
// Created by Shinichiro Oba on 2021/03/18.
//
import UIKit
import WebKit
@bricklife
bricklife / main.py
Last active Jul 4, 2020
Autonomous running train in Pybricks
View main.py
from pybricks.hubs import CityHub
from pybricks.pupdevices import DCMotor, ColorDistanceSensor
from pybricks.parameters import Port, Color
from pybricks.tools import wait
hub = CityHub()
motor = DCMotor(Port.A)
color_sensor = ColorDistanceSensor(Port.B)
def wait_for_color(color):
@bricklife
bricklife / LEGO SPIKE Prime JSON command examples.md
Last active Jan 11, 2021
LEGO SPIKE Prime JSON command examples
View LEGO SPIKE Prime JSON command examples.md

System

{"i":"EMWW","m":"get_firmware_info","p":{}}
{"m":"trigger_current_state","p":{}}
{"m":"program_modechange","p":{"mode":"play"}} // "mode": "play" or "download"
{"i":"ESGe","m":"set_hub_name","p":{"name":"U1BJS0U="}} // "name": Base64 string

Motor

View ESP32-1Button-BLE-Keyboard.ino
#include <BleKeyboard.h> // https://github.com/T-vK/ESP32-BLE-Keyboard
BleKeyboard bleKeyboard;
bool pressing = false;
void setup() {
pinMode(25, INPUT_PULLUP); // A1 pin
bleKeyboard.begin();
}
View Digispark-1Button-Keyboard.ino
#include "DigiKeyboard.h"
bool pressing = false;
void setup() {
pinMode(0, INPUT);
digitalWrite(0, HIGH); // Pull Up
}
void loop() {
View Teensyduino-1Button-Keyboard.ino
#include <Bounce.h>
Bounce button = Bounce(1, 10);
void setup() {
pinMode(1, INPUT_PULLUP);
}
void loop() {
button.update();
@bricklife
bricklife / spike_send.py
Created May 21, 2020
Send command to SPIKE from EV3
View spike_send.py
#!/usr/bin/env pybricks-micropython
from pybricks.hubs import EV3Brick
from pybricks.tools import wait
from pybricks.parameters import Button
from connection import SpikePrimeStreamReader
# Add send_command method into SpikePrimeStreamReader class
def send_command(self, command):
self.sock.send((command + '\r').encode())
@bricklife
bricklife / SPIKE_Prime_REPL.txt
Last active Jan 16, 2020
REPL mode on LEGO Education SPIKE Prime hub
View SPIKE_Prime_REPL.txt
MicroPython v1.9.4-1146-gca9944357 on 2019-10-03; LEGO Technic Large Hub with STM32F413xx
Type "help()" for more information.
>>> help()
Welcome to MicroPython!
For online help please visit http://micropython.org/help/.
Quick overview of commands for the board:
hub.info() -- print some general information
hub.status() -- print sensor data
@bricklife
bricklife / main.py
Last active Jan 16, 2020
main.py in LEGO Education SPIKE Prime Hub
View main.py
import gc
import micropython
import hub_runtime
micropython.alloc_emergency_exception_buf(256)
hub_runtime.start()
@bricklife
bricklife / overwrite_main.py
Last active Jan 16, 2020
Overwriting main.py in LEGO Education SPIKE Prime Hub
View overwrite_main.py
import io
f = io.open('main.py', 'w')
f.write('''
import hub
import time
while True:
hub.display.show(hub.Image('00000:00000:00900:00000:00000:'))
time.sleep_ms(500)