def main():
    print('alevel test is running.')
    CWriter.set_textpos(ssd, 0, 0)  # In case previous tests have altered it
    wri = CWriter(ssd, arial10, GREEN, BLACK, verbose=False)
    wri.set_clip(True, True, False)
    acc = pyb.Accel()
    dial = Dial(wri,
                5,
                5,
                height=75,
                ticks=12,
                bdcolor=None,
                label='Tilt Pyboard',
                style=Dial.COMPASS,
                pip=YELLOW)  # Border in fg color
    ptr = Pointer(dial)
    scale = 1 / 40
    while True:
        x, y, z = acc.filtered_xyz()
        # Depending on relative alignment of display and Pyboard this line may
        # need changing: swap x and y or change signs so arrow points in direction
        # board is tilted.
        ptr.value(-y * scale + 1j * x * scale, YELLOW)
        refresh(ssd)
        utime.sleep_ms(200)
def compass():
    dial = Dial(wri,
                5,
                5,
                height=75,
                ticks=12,
                bdcolor=None,
                label='Direction',
                style=Dial.COMPASS)
    ptr = Pointer(dial)
    ptr.value(1 + 1j)
async def compass(evt):
    wri = Writer(ssd, arial10, verbose=False)
    wri.set_clip(False, False, False)
    v1 = 0 + 0.9j
    v2 = exp(0 - (pi / 6) * 1j)
    dial = Dial(wri,
                5,
                5,
                height=75,
                ticks=12,
                bdcolor=None,
                label='Direction',
                style=Dial.COMPASS)
    ptr = Pointer(dial)
    while True:
        ptr.value(v1)
        v1 *= v2
        await evt.wait()
Exemple #4
0
def compass(x):
    print('Compass test.')
    refresh(ssd, True)  # Clear any prior image
    dial = Dial(wri, 5, 5, height = 75, bdcolor=None, label=50, style = Dial.COMPASS)
    bearing = Pointer(dial)
    bearing.value(0 + 1j, RED)
    dh = cmath.rect(1, -cmath.pi/30)  # Rotate by 6 degrees CW
    for n in range(x):
        utime.sleep_ms(200)
        bearing.value(bearing.value() * dh, RED)
        refresh(ssd)
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 aclock():
    uv = lambda phi : cmath.rect(1, phi)  # Return a unit vector of phase phi
    pi = cmath.pi
    days = ('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday',
            'Sunday')
    months = ('Jan', 'Feb', 'March', 'April', 'May', 'June', 'July',
              'Aug', 'Sept', 'Oct', 'Nov', 'Dec')
    # Instantiate CWriter
    CWriter.set_textpos(ssd, 0, 0)  # In case previous tests have altered it
    wri = CWriter(ssd, arial10, GREEN, BLACK, verbose=False)
    wri.set_clip(True, True, False)

    # Instantiate displayable objects
    dial = Dial(wri, 2, 2, height = 75, ticks = 12, bdcolor=None, label=120, pip=False)  # Border in fg color
    lbltim = Label(wri, 5, 85, 35)
    hrs = Pointer(dial)
    mins = Pointer(dial)
    secs = Pointer(dial)

    hstart =  0 + 0.7j  # Pointer lengths and position at top
    mstart = 0 + 0.92j
    sstart = 0 + 0.92j 
    while True:
        t = utime.localtime()
        hrs.value(hstart * uv(-t[3]*pi/6 - t[4]*pi/360), YELLOW)
        mins.value(mstart * uv(-t[4] * pi/30), YELLOW)
        secs.value(sstart * uv(-t[5] * pi/30), RED)
        lbltim.value('{:02d}.{:02d}.{:02d}'.format(t[3], t[4], t[5]))
        dial.text('{} {} {} {}'.format(days[t[6]], t[2], months[t[1] - 1], t[0]))
        refresh(ssd)
        utime.sleep(1)
def aclock():
    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)
    secs = Pointer(dial)

    hstart =  0 + 0.7j  # Pointer lengths and position at top
    mstart = 0 + 0.92j
    sstart = 0 + 0.92j 
    while True:
        t = utime.localtime()
        hang = -t[3]*pi/6 - t[4]*pi/360  # Angles of hour and minute hands
        mang = -t[4] * pi/30
        sang = -t[5] * pi/30
        if abs(hang - mang) < pi/360:  # Avoid overlap of hr and min hands
            hang += pi/30  # which is visually confusing. Add slight lag to hrs
        hrs.value(hstart * uv(hang))
        mins.value(mstart * uv(mang))
        secs.value(sstart * uv(sang))
        lbltim.value('{:02d}.{:02d}.{:02d}'.format(t[3], t[4], t[5]))
        lbldat.value('{} {} {} {}'.format(days[t[6]], t[2], months[t[1] - 1], t[0]))
        refresh(ssd)
        utime.sleep(1)
Exemple #8
0
async def aclock():
    do_connect.do_connect()
    asyncio.create_task(set_rtc())
    asyncio.create_task(ramcheck())
    uv = lambda phi: cmath.rect(1, phi)  # Return a unit vector of phase phi
    pi = cmath.pi
    days = ('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday',
            'Sunday')
    months = ('January', 'February', 'March', 'April', 'May', 'June', 'July',
              'August', 'September', 'October', 'November', 'December')
    # Instantiate CWriter
    CWriter.set_textpos(ssd, 0, 0)  # In case previous tests have altered it
    wri = CWriter(ssd, font, GREEN, BLACK, verbose=False)
    wri.set_clip(True, True, False)

    # Instantiate displayable objects
    dial = Dial(wri, 2, 2, height=130, ticks=12,
                bdcolor=None)  # Border in fg color
    lbltim = Label(wri, 140, 2, 130)
    lblday = Label(wri, 170, 2, 130)
    lblmonth = Label(wri, 190, 2, 130)
    lblyr = Label(wri, 210, 2, 130)
    hrs = Pointer(dial)
    mins = Pointer(dial)
    secs = Pointer(dial)

    hstart = 0 + 0.7j  # Pointer lengths and position at top
    mstart = 0 + 0.92j
    sstart = 0 + 0.92j
    t = time.localtime()
    while True:
        hrs.value(hstart * uv(-t[3] * pi / 6 - t[4] * pi / 360), YELLOW)
        mins.value(mstart * uv(-t[4] * pi / 30 - t[5] * pi / 1800), YELLOW)
        secs.value(sstart * uv(-t[5] * pi / 30), RED)
        lbltim.value('{:02d}.{:02d}.{:02d} {}'.format(t[3], t[4], t[5],
                                                      'BST' if bst else 'UTC'))
        lblday.value('{}'.format(days[t[6]]))
        lblmonth.value('{} {}'.format(t[2], months[t[1] - 1]))
        lblyr.value('{}'.format(t[0]))
        refresh(ssd)
        st = t
        while st == t:
            await asyncio.sleep_ms(100)
            t = time.localtime()
def clock(x):
    print('Clock test.')
    refresh(ssd, True)  # Clear any prior image
    lbl = Label(wri, 5, 85, 'Clock')
    dial = Dial(wri, 5, 5, height=75, ticks=12, bdcolor=None,
                label=50)  # Border in fg color
    hrs = Pointer(dial)
    mins = Pointer(dial)
    hrs.value(0 + 0.7j, RED)
    mins.value(0 + 0.9j, YELLOW)
    dm = cmath.rect(1, -cmath.pi / 30)  # Rotate by 1 minute (CW)
    dh = cmath.rect(1, -cmath.pi / 1800)  # Rotate hours by 1 minute
    for n in range(x):
        refresh(ssd)
        utime.sleep_ms(200)
        mins.value(mins.value() * dm, YELLOW)
        hrs.value(hrs.value() * dh, RED)
        dial.text('ticks: {}'.format(n))
    lbl.value('Done')