👷: Difference between revisions
Jump to navigation
Jump to search
(T-Minus ~1 hour) |
(→µPython: nums == digits 0-9) |
||
| Line 4: | Line 4: | ||
== µPython == | == µPython == | ||
=== Digit Dev === | |||
<pre> | |||
#009 ⁂ lcd | |||
#600 ⌚ +buzz | |||
#630 re-write: lcd, encoder | |||
#060 swap pin 2 to 0 | |||
#066 +temp & backlite | |||
#666 nub'd | |||
#NYE 2018 Hard Hat | |||
import machine | |||
from encoder import Encoder | |||
from machine import Pin | |||
from time import sleep_ms | |||
from time import ticks_us | |||
from time import ticks_diff | |||
from utime import localtime | |||
from neopixel import NeoPixel | |||
VERSION = "#NYE -11:00" | |||
INTERVAL = 100 | |||
BUZZ_PIN = const(12) | |||
NEO_PIN = const(3) | |||
buzz = Pin(BUZZ_PIN, Pin.OUT) | |||
neo = Pin(3, Pin.OUT) | |||
np = NeoPixel(neo, 34) | |||
nums = [ | |||
(1,1,1,1,1,1,0,0,0,1,1,1,1,1,1), | |||
(0,0,0,0,0,1,1,1,1,1,0,0,0,0,0), | |||
(1,0,1,1,1,1,0,1,0,1,1,1,1,0,1), | |||
(1,1,1,1,1,1,0,1,0,1,1,0,1,0,1), | |||
(1,1,1,1,1,0,0,1,0,0,0,0,1,1,1), | |||
(1,1,1,0,1,1,0,1,0,1,1,0,1,1,1), | |||
(1,1,1,0,1,1,0,1,0,1,1,1,1,1,1), | |||
(1,1,1,1,1,1,0,0,0,0,0,0,0,0,1), | |||
(1,1,1,1,1,1,0,1,0,1,1,1,1,1,1), | |||
(1,1,1,1,1,1,0,1,0,1,1,0,1,1,1)] | |||
def timed_function(f, *args, **kwargs): | |||
myname = str(f).split(' ')[1] | |||
def new_func(*args, **kwargs): | |||
t = ticks_us() | |||
result = f(*args, **kwargs) | |||
delta = ticks_diff(ticks_us(), t) | |||
print('Function {} Time = {:6.3f}ms'.format(myname, delta/1000)) | |||
return result | |||
return new_func | |||
#@timed_function | |||
def ver(): | |||
print(VERSION) | |||
ver() | |||
def chirp(t = 10): | |||
buzz.value(True) | |||
sleep_ms(t) | |||
buzz.value(False) | |||
chirp() | |||
buzz = Pin(12, Pin.OUT) | |||
chirp() | |||
def digit(num): | |||
i = 0; | |||
while i < 15: | |||
if nums[num][i]: | |||
np[i+4] = (0, 0, 22) | |||
i += 1 | |||
def main(): | |||
blink = 0 | |||
while 1: | |||
t = localtime() | |||
i = 0 | |||
while i < 34: | |||
np[i] = (0, 0, 0) | |||
i += 1 | |||
i = (blink * 5) + 4 | |||
j = 0 | |||
while j < 5: | |||
np[i+j] = [33, 0, 0] | |||
j += 1 | |||
np[blink] = (0, 10, 0) | |||
blink += 1 | |||
if blink > 5: | |||
blink = 0 | |||
np.write() | |||
sleep_ms(INTERVAL) | |||
main() | |||
</pre> | |||
<pre> | |||
#display 0 | |||
digit(0) | |||
np.write() | |||
</pre> | |||
=== Test Code === | |||
Requires LCD & Encoder libraries: https://github.com/mbirth/wipy-upcd8544/blob/master/upcd8544.py | |||
<pre> | <pre> | ||
Revision as of 02:07, 1 January 2018
Blink'n hard hat project page...
µPython
Digit Dev
#009 ⁂ lcd
#600 ⌚ +buzz
#630 re-write: lcd, encoder
#060 swap pin 2 to 0
#066 +temp & backlite
#666 nub'd
#NYE 2018 Hard Hat
import machine
from encoder import Encoder
from machine import Pin
from time import sleep_ms
from time import ticks_us
from time import ticks_diff
from utime import localtime
from neopixel import NeoPixel
VERSION = "#NYE -11:00"
INTERVAL = 100
BUZZ_PIN = const(12)
NEO_PIN = const(3)
buzz = Pin(BUZZ_PIN, Pin.OUT)
neo = Pin(3, Pin.OUT)
np = NeoPixel(neo, 34)
nums = [
(1,1,1,1,1,1,0,0,0,1,1,1,1,1,1),
(0,0,0,0,0,1,1,1,1,1,0,0,0,0,0),
(1,0,1,1,1,1,0,1,0,1,1,1,1,0,1),
(1,1,1,1,1,1,0,1,0,1,1,0,1,0,1),
(1,1,1,1,1,0,0,1,0,0,0,0,1,1,1),
(1,1,1,0,1,1,0,1,0,1,1,0,1,1,1),
(1,1,1,0,1,1,0,1,0,1,1,1,1,1,1),
(1,1,1,1,1,1,0,0,0,0,0,0,0,0,1),
(1,1,1,1,1,1,0,1,0,1,1,1,1,1,1),
(1,1,1,1,1,1,0,1,0,1,1,0,1,1,1)]
def timed_function(f, *args, **kwargs):
myname = str(f).split(' ')[1]
def new_func(*args, **kwargs):
t = ticks_us()
result = f(*args, **kwargs)
delta = ticks_diff(ticks_us(), t)
print('Function {} Time = {:6.3f}ms'.format(myname, delta/1000))
return result
return new_func
#@timed_function
def ver():
print(VERSION)
ver()
def chirp(t = 10):
buzz.value(True)
sleep_ms(t)
buzz.value(False)
chirp()
buzz = Pin(12, Pin.OUT)
chirp()
def digit(num):
i = 0;
while i < 15:
if nums[num][i]:
np[i+4] = (0, 0, 22)
i += 1
def main():
blink = 0
while 1:
t = localtime()
i = 0
while i < 34:
np[i] = (0, 0, 0)
i += 1
i = (blink * 5) + 4
j = 0
while j < 5:
np[i+j] = [33, 0, 0]
j += 1
np[blink] = (0, 10, 0)
blink += 1
if blink > 5:
blink = 0
np.write()
sleep_ms(INTERVAL)
main()
#display 0 digit(0) np.write()
Test Code
Requires LCD & Encoder libraries: https://github.com/mbirth/wipy-upcd8544/blob/master/upcd8544.py
#009 ⁂ lcd
#600 ⌚ +buzz
#630 re-write: lcd, encoder
#060 swap pin 2 to 0
#066 +temp & backlite
#666 nub'd
#NYE 2018 Hard Hat
import upcd8544
import framebuf
import machine
from encoder import Encoder
from machine import Pin
from machine import PWM
from machine import SPI
from time import sleep_ms
from time import ticks_us
from time import ticks_diff
from utime import localtime
from neopixel import NeoPixel
VERSION = "#NYE -3:59:00"
INTERVAL = 100
PUSH_PIN = const(0)
BUZZ_PIN = const(12)
NEO_PIN = const(3)
LCD_RST = const(0)
LCD_CE = const(16)
LCD_DC = const(15)
push = Pin(PUSH_PIN, Pin.IN)
buzz = Pin(BUZZ_PIN, Pin.OUT)
enc = Encoder(5, 4, Pin.PULL_UP, 4, 0, 255)
neo = Pin(3, Pin.OUT)
np = NeoPixel(neo, 34)
pushed = False
count = 0
temp = 0
def timed_function(f, *args, **kwargs):
myname = str(f).split(' ')[1]
def new_func(*args, **kwargs):
t = ticks_us()
result = f(*args, **kwargs)
delta = ticks_diff(ticks_us(), t)
print('Function {} Time = {:6.3f}ms'.format(myname, delta/1000))
return result
return new_func
#@timed_function
def ver():
print(VERSION)
ver()
def chirp(t = 10):
buzz.high()
sleep_ms(t)
buzz.low()
chirp()
def push_handler(p):
global pushed
pushed = True
print("PUSH")
push.irq(trigger=Pin.IRQ_FALLING, handler=push_handler)
spi = SPI(1, baudrate=80000000, polarity=0, phase=0)
lcd = upcd8544.PCD8544(spi, Pin(0), Pin(16), Pin(15), Pin(0))
width = 84
height = 48
pages = height // 8
buffer = bytearray(pages * width)
framebuf = framebuf.FrameBuffer1(buffer, width, height)
framebuf.text("red/watch", 0, 1, 1)
framebuf.text(VERSION, 0, 8, 1)
lcd.data(buffer)
buzz = Pin(12, Pin.OUT)
chirp()
def main():
global lcd, temp, framebuf, pushed, count
bar = True
blink = 0
while 1:
t = localtime()
count = enc.value
if pushed:
pushed = False
chirp()
i = 0
while i < 34:
np[i] = (0, 0, 0)
i += 1
i = (blink * 5) + 4
j = 0
while j < 5:
np[i+j] = [33, 0, 0]
j += 1
np[blink] = (0, 10, 0)
blink += 1
if blink > 5:
blink = 0
np.write()
framebuf.fill(0)
framebuf.text("2017-2018", 4, 0, 1)
framebuf.text(VERSION, 2, 40, 1)
framebuf.text(" {:02d}:{:02d}:{:02d}".format(t[3], t[4], t[5]), 0, 16, 1)
if bar:
bar = False
for x in range(0,84):
framebuf.pixel(x, 32, 1)
else:
bar = True
lcd.data(buffer)
sleep_ms(INTERVAL)
main()