Skip to content

Instantly share code, notes, and snippets.

View RRMoelker's full-sized avatar

Ruurd Moelker RRMoelker

View GitHub Profile
@RRMoelker
RRMoelker / boot.py
Created July 13, 2016 09:55
WiPy connect WiFi network on boot
# boot.py -- run on boot-up
# can run arbitrary Python, but best to keep it minimal
#
# WiPy WiFi setup, augmented code from:
# http://micropython.org/resources/docs/en/latest/wipy/wipy/tutorial/wlan.html#assigning-a-static-ip-address-when-booting
import machine
from network import WLAN
IP = '192.168.1.42'
@RRMoelker
RRMoelker / main.py
Created July 13, 2016 11:06
WiPy hello world blink Heartbeat LED
import time
import wipy
while True:
wipy.heartbeat(False) # disable the heartbeat
time.sleep_ms(100)
wipy.heartbeat(True) # enable the heartbeat
time.sleep_ms(100)
@RRMoelker
RRMoelker / main.py
Created July 13, 2016 11:17
WiPy hello world blink Heartbeat LED using pin 25
import time
from machine import Pin
led = Pin('GP25', mode=Pin.OUT)
while True:
led(0) # turn off the heartbeat LED
time.sleep_ms(100)
led(1) # turn on the heartbeat LED
time.sleep_ms(100)
@RRMoelker
RRMoelker / main.py
Created July 14, 2016 12:32
Hello servo WiPy
#
# Rotate servo over full rotational range
#
import time
from machine import Pin, Timer
# Servo specific constants
PULSE_MIN = 900 # in us, actually bit higher than specs indicate
PULSE_MAX = 2100 # in us
FREQUENCY = 50 # Hz
@RRMoelker
RRMoelker / main.py
Created July 14, 2016 13:17
Hello servo using WiPy servo library https://github.com/RRMoelker/WiPy-servo
# coding=utf-8
#
# Rotate servo over full rotational range
#
import time
from machine import Pin
from servo import Servo
# Configuration
@RRMoelker
RRMoelker / upload.sh
Created July 14, 2016 13:19
WiPy hello servo using servo lib lftp upload shell script
#!/bin/bash
# first argument is WiPy ip
lftp -u micro,python $1 << EOF
cd /flash
put main.py
put WiPy-servo/servo.py
@RRMoelker
RRMoelker / main.py
Created July 14, 2016 15:43
Food dispenser WiPy food cycle with stuttering motion
# coding=utf-8
#
# Loop through food delivery cycle
#
import time
from machine import Pin
from servo import Servo
led = Pin('GP25', mode=Pin.OUT)
@RRMoelker
RRMoelker / gist:af11d53ab85ce361019f14504856bb30
Created April 25, 2017 05:54
Custom tag highlighting JS
(function(){
const knownTags = ['address', 'article', 'aside', 'footer', 'h1','h2','h3','h4','h5','h6', 'header', 'hgroup', 'nav', 'section', 'dd', 'div', 'dl', 'dt', 'figcaption', 'figure', 'hr', 'li', 'main', 'ol', 'p', 'pre', 'ul', 'a', 'abbr', 'b', 'bdi', 'bdo', 'br', 'cite', 'code', 'data', 'dfn', 'em', 'i', 'kbd', 'mark', 'q', 'rp', 'rt', 'rtc', 'ruby', 's', 'samp', 'small', 'span', 'strong', 'sub', 'sup', 'time', 'u', 'var', 'wbr','caption', 'col', 'colgroup', 'table', 'tbody', 'td', 'tfoot', 'th', 'thead', 'tr', 'button', 'datalist', 'fieldset', 'form', 'input', 'label', 'legend', 'meter', 'optgroup', 'option', 'output', 'progress', 'select', 'textarea' ];
const notCss = knownTags.map(tag => `:not( ${ tag } )`).join('');
const nodes = document.querySelectorAll(`body ${ notCss }`);
const nodesArray = Array.prototype.slice.call(nodes);
nodesArray.map( node => {
const outer = document.createElement('div');
@RRMoelker
RRMoelker / asyncio_pipeline_basic.py
Last active November 12, 2021 13:33
Dead simple asyncio pipeline
"""
Example program for basic asyncio pipeline.
Program takes string as input and converts it to upper case.
For sake of simplicity missing some "features", most notably error handling is absent.
Errors will silenty prevent program completion in many cases.
"""
import asyncio
from dataclasses import dataclass
@RRMoelker
RRMoelker / asyncio_pipeline_wait.py
Last active July 24, 2019 19:16
Dead simple asyncio pipeline with random waiting
"""
Example program for asyncio pipeline with varying stage times.
Program takes string as input and converts it to upper case.
"""
import asyncio
import random
from dataclasses import dataclass