def aclock():
    rtc = pyb.RTC()
    uv = lambda phi: cmath.rect(1, phi)  # Return a unit vector of phase phi
    pi = cmath.pi
    days = ('Mon', 'Tue', 'Wed', 'Thur', 'Fri', 'Sat', 'Sun')
    months = ('Jan', 'Feb', 'March', 'April', 'May', 'June', 'July', 'Aug',
              'Sept', 'Oct', 'Nov', 'Dec')
    # Instantiate Writer
    Writer.set_textpos(ssd, 0, 0)  # In case previous tests have altered it
    wri = Writer(ssd, font_small, verbose=False)
    wri.set_clip(True, True, False)
    wri_tim = Writer(ssd, font_large, verbose=False)
    wri_tim.set_clip(True, True, False)

    # Instantiate displayable objects
    dial = Dial(wri, 2, 2, height=215, ticks=12, bdcolor=None, pip=True)
    lbltim = Label(wri_tim, 50, 230, '00.00.00')
    lbldat = Label(wri, 100, 230, 100)
    hrs = Pointer(dial)
    mins = Pointer(dial)

    hstart = 0 + 0.7j  # Pointer lengths and position at top
    mstart = 0 + 0.92j
    while True:
        t = rtc.datetime(
        )  # (year, month, day, weekday, hours, minutes, seconds, subseconds)
        hang = -t[4] * pi / 6 - t[5] * pi / 360  # Angles of hands in radians
        mang = -t[5] * pi / 30
        if abs(hang -
               mang) < pi / 360:  # Avoid visually confusing overlap of hands
            hang += pi / 30  # by making hr hand lag slightly
        hrs.value(hstart * uv(hang))
        mins.value(mstart * uv(mang))
        lbltim.value('{:02d}.{:02d}'.format(t[4], t[5]))
        lbldat.value('{} {} {} {}'.format(days[t[3] - 1], t[2],
                                          months[t[1] - 1], t[0]))
        refresh(ssd)
        # Power saving: only refresh every 30s
        for _ in range(30):
            upower.lpdelay(1000)
            ssd.update()  # Toggle VCOM
def test(*pin_names, rising=True):
    wups = [
        upower.WakeupPin(pyb.Pin(name), rising=rising) for name in pin_names
    ]
    reason = machine.reset_cause()  # Why have we woken?
    if reason in (machine.PWRON_RESET, machine.HARD_RESET,
                  machine.SOFT_RESET):  # first boot
        rtc.datetime(
            (2020, 8, 6, 4, 13, 0, 0, 0))  # Code to run on 1st boot only
        upower.savetime()
        if upower.bkpram_ok():  # backup RAM holds valid data: battery backed
            light(2)  # Blue only
        else:  # Boot with no backup battery, data is garbage
            light(0, 1, 2)  # White
    elif reason == machine.DEEPSLEEP_RESET:
        reason = upower.why()
        if reason == 'WAKEUP':
            light(0, 1, 2)  # White on timer wakeup
            upower.savetime()
        elif reason == 'X3':  # red
            light(0)
        elif reason == 'X1':  # green
            light(1)
        elif reason == 'C1':
            light(2)  # Blue
        elif reason == 'C13':
            light(0, 1)  # Red and green
        else:
            upower.cprint('Unknown: reset?')  # Prints if a UART is configured

    upower.lpdelay(500)  # ensure LEDs visible before standby turns it off
    while any((p.state() for p in wups)):
        upower.lpdelay(50)  # Wait for wakeup signals to go away
    upower.lpdelay(50)  # Wait out any contact bounce

    # demo of not resetting the wakeup timer after a pin interrupt
    try:  # ms_left can fail in response to various coding errors
        timeleft = upower.ms_left(10000)
    except upower.RTCError:
        timeleft = 10000  # Coding error: uninitialised - just restart the timer
    # Set a minimum sleep duration: too short and it uses less power to stay awake
    # In real apps this might be longer or you might deal with it in other ways.
    timeleft = max(timeleft, 1000)
    rtc.wakeup(timeleft)
    # These calls reconfigure hardware and should be done last, shortly before standby()
    for p in wups:
        p.enable()
    if not upower.usb_connected:
        pyb.standby()  # Set pins hi-z and turn LEDs off
    else:
        light(1)  # Green LED: debugging session.
# Copyright Peter Hinch
# V0.4 10th October 2016 Now uses machine.reset_cause()
# Flashes leds at 30 second intervals courtesy of two concurrent timers
# (each times out at one minute intervals).
# Note that the Pyboard flashes the green LED briefly on waking from standby.
import stm, pyb, upower, machine

red, green, yellow = (pyb.LED(x) for x in range(1, 4)
                      )  # LED(3) is blue, not yellow, on D series
rtc = pyb.RTC()
rtc.wakeup(
    None
)  # If we have a backup battery clear down any setting from a previously running program
reason = machine.reset_cause()  # Why have we woken?
if reason == machine.PWRON_RESET or reason == machine.HARD_RESET:  # first boot
    rtc.datetime((2020, 8, 6, 4, 13, 0, 0, 0))  # Code to run on 1st boot only
    aa = upower.Alarm('a')
    aa.timeset(second=39)
    ab = upower.Alarm('b')
    ab.timeset(second=9)
    red.on()
elif reason == machine.DEEPSLEEP_RESET:
    reason = upower.why()
    if reason == 'ALARM_A':
        green.on()
    elif reason == 'ALARM_B':
        yellow.on()

upower.lpdelay(1000)  # Let LED's be seen!
pyb.standby()
    if reason == "WAKEUP":  # green and yellow on timer wakeup
        leds[1].on()
        leds[2].on()
        upower.savetime()
    elif reason == "TAMPER":  # red
        leds[0].on()
    elif reason == "X1":  # red and green on X1 rising edge
        leds[0].on()
        leds[1].on()
    else:
        upower.cprint("Unknown: reset?")  # Prints if a UART is configured

t = rtc.datetime()[4:7]
upower.cprint("{:02d}.{:02d}.{:02d}".format(t[0], t[1], t[2]))

upower.lpdelay(500)  # ensure LED visible before standby turns it off
tamper.wait_inactive()  # Wait for tamper signal to go away
wkup.wait_inactive()
upower.lpdelay(50)  # Wait out any contact bounce
# demo of not resetting the wakeup timer after a pin interrupt
try:  # ms_left can fail in response to various coding errors
    timeleft = upower.ms_left(10000)
except upower.RTCError:
    timeleft = 10000  # Coding error: uninitialised - just restart the timer
timeleft = max(timeleft, 1000)  # Set a minimum sleep duration: too short and it uses less power to stay awake
# In real apps this might be longer or you might deal with it in other ways.
rtc.wakeup(timeleft)
# These calls reconfigure hardware and should be done last, shortly before standby()
tamper.enable()
wkup.enable()
if not upower.usb_connected:
 def wait_ready():
     while not ssd.ready():
         upower.lpdelay(1000)
# epd29_sync.py Demo of synchronous code on 2.9" EPD display

# Released under the MIT License (MIT). See LICENSE.
# Copyright (c) 2020 Peter Hinch

# color_setup must set landcsape True, asyn False and must not set demo_mode

from math import pi, sin
import upower
import machine
import pyb
pon = machine.Pin('Y5', machine.Pin.OUT_PP,
                  value=1)  # Power on before instantiating display
upower.lpdelay(1000)  # Give the valves (tubes) time to warm up :)
from color_setup import ssd  # Instantiate
from gui.core.writer import Writer
from gui.core.nanogui import refresh
from gui.core.fplot import CartesianGraph, Curve
from gui.widgets.meter import Meter
from gui.widgets.label import Label
from gui.widgets.dial import Dial, Pointer

# Fonts
import gui.fonts.arial10 as arial10
import gui.fonts.freesans20 as large

wri = Writer(ssd, arial10, verbose=False)
wri.set_clip(False, False, False)

wri_large = Writer(ssd, large, verbose=False)
wri_large.set_clip(False, False, False)
Beispiel #7
0
elif reason == 'WAKEUP':  # green and yellow on timer wakeup
    leds[1].on()
    leds[2].on()
    upower.savetime()
elif reason == 'TAMPER':  # red
    leds[0].on()
elif reason == 'X1':  # red and green on X1 rising edge
    leds[0].on()
    leds[1].on()
else:
    upower.cprint('Unknown: reset?')  # Prints if a UART is configured

t = rtc.datetime()[4:7]
upower.cprint('{:02d}.{:02d}.{:02d}'.format(t[0], t[1], t[2]))

upower.lpdelay(500)  # ensure LED visible before standby turns it off
tamper.wait_inactive()  # Wait for tamper signal to go away
wkup.wait_inactive()
upower.lpdelay(50)  # Wait out any contact bounce
# demo of not resetting the wakeup timer after a pin interrupt
try:  # ms_left can fail in response to various coding errors
    timeleft = upower.ms_left(10000)
except upower.RTCError:
    timeleft = 10000  # Coding error: uninitialised - just restart the timer
timeleft = max(
    timeleft, 1000
)  # Set a minimum sleep duration: too short and it uses less power to stay awake
# In real apps this might be longer or you might deal with it in other ways.
rtc.wakeup(timeleft)
# These calls reconfigure hardware and should be done last, shortly before standby()
tamper.enable()
        leds[2].on()
        upower.savetime()
    elif reason == 'TAMPER':  # red
        leds[0].on()
    elif reason == 'X1':  # red and green on X1 rising edge
        leds[0].on()
        leds[1].on()
    else:
        # Prints if a UART is configured
        upower.cprint('Unknown: reset?')

t = rtc.datetime()[4:7]
upower.cprint('{:02d}.{:02d}.{:02d}'.format(t[0], t[1], t[2]))

# ensure LED visible before standby turns it off
upower.lpdelay(500)

# Wait for tamper signal to go away
tamper.wait_inactive()
wkup.wait_inactive()
upower.lpdelay(50)  # Wait out any contact bounce
# demo of not resetting the wakeup timer after a pin interrupt
try:  # ms_left can fail in response to various coding errors
    timeleft = upower.ms_left(10000)
except upower.RTCError:
    # Coding error: uninitialised - just restart the timer
    timeleft = 10000
# Set a minimum sleep duration: too short and it uses less power to stay awake
timeleft = max(timeleft, 1000)
# In real apps this might be longer or you might deal with it in other ways.
rtc.wakeup(timeleft)
# alarm.py Demonstrate using RTC alarms to exit pyb.standby()

# Copyright Peter Hinch
# V0.3 13th February 2016
# Flashes leds at 30 second intervals courtesy of two concurrent timers
# (each times out at one minute intervals).
# Note that the Pyboard flashes the green LED briefly on waking from standby.
import stm, pyb, upower

red, green, yellow, blue = (pyb.LED(x) for x in range(1, 5))
rtc = pyb.RTC()
rtc.wakeup(None) # If we have a backup battery clear down any setting from a previously running program
reason = upower.why()                           # Why have we woken?
if reason == 'BOOT':                            # first boot
    rtc.datetime((2015, 8, 6, 4, 13, 0, 0, 0))  # Code to run on 1st boot only
    aa = upower.Alarm('a')
    aa.timeset(second = 39)
    ab = upower.Alarm('b')
    ab.timeset(second = 9)
    red.on()
elif reason == 'POWERUP':                       # Backup battery in place
    blue.on()
elif reason == 'ALARM_A':
    green.on()
elif reason == 'ALARM_B':
    yellow.on()

upower.lpdelay(1000)     # Let LED's be seen!
pyb.standby()