示例#1
0
def seq():
    print('Time sequence test - sine and cosine.')
    refresh(st7735, True)  # Clear any prior image
    # y axis at t==now, no border
    g = CartesianGraph(wri,
                       32,
                       2,
                       height=80,
                       xorigin=10,
                       fgcolor=False,
                       gridcolor=LIGHTGREEN,
                       bdcolor=WHITE)
    #     tsy = TSequence(g, YELLOW, 50)
    #     tsr = TSequence(g, RED, 50)
    lbl = Label(wri, 10, 5, 'label')
    lbl.value("DAMPED OSCILLATOR")
    plt = TSequence(g, WHITE, 200)
    r = 0.9
    p = 0
    for t in range(300):
        g.clear()
        #         tsy.add(0.9*math.sin(t/10))
        #         tsr.add(0.4*math.cos(t/10))
        plt.add(r * math.cos(t / 10))
        r = r - 0.003
        refresh(st7735)
        #         print(r)
        utime.sleep_ms(1)
        p = p + 1
示例#2
0
def clock(x):
    print('Clock test.')
    refresh(st7735, 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(st7735)
        utime.sleep_ms(200)
        mins.value(mins.value() * dm, YELLOW)
        hrs.value(hrs.value() * dh, RED)
        dial.text('ticks: {}'.format(n))
    lbl.value('Done')
示例#3
0
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 = ('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[4] * pi / 6 - t[
            5] * pi / 360  # Angles of hour and minute hands
        mang = -t[5] * pi / 30
        sang = -t[6] * 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 hts
        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)
示例#5
0
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')

    CWriter.set_textpos(st7735, 0, 0)  # In case previous tests have altered it
    wri = CWriter(st7735, arial10, GREEN, BLACK, verbose=False)
    wri.set_clip(True, True, False)

    # Instantiate displayable objects
    refresh(st7735, True)  # Clear any prior image
    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 = cetTime()
        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(st7735)
        utime.sleep(1)
示例#6
0
def fields(use_spi=False, soft=True):
    ssd = setup(use_spi, soft)  # Create a display instance
    Writer.set_textpos(ssd, 0, 0)  # In case previous tests have altered it
    wri = Writer(ssd, fixed, verbose=False)
    wri.set_clip(False, False, False)
    textfield = Label(wri, 0, 2, wri.stringlen('longer'))
    numfield = Label(wri, 25, 2, wri.stringlen('99.99'), bdcolor=None)
    countfield = Label(wri, 0, 90, wri.stringlen('1'))
    n = 1
    for s in ('short', 'longer', '1', ''):
        textfield.value(s)
        numfield.value('{:5.2f}'.format(int.from_bytes(uos.urandom(2),'little')/1000))
        countfield.value('{:1d}'.format(n))
        n += 1
        refresh(ssd)
        utime.sleep(2)
    textfield.value('Done', True)
    refresh(ssd)
示例#7
0
def meter():
    print('meter')

    refresh(st7735, True)  # Clear any prior image
    title = Label(wri,
                  2,
                  10,
                  'SHT30 measurements',
                  fgcolor=Display.WHITE,
                  bdcolor=Display.WHITE)
    tempLabel = Label(wri,
                      110,
                      2,
                      '32.4 deg C',
                      fgcolor=Display.WHITE,
                      bdcolor=Display.BLACK)
    humiLabel = Label(wri,
                      110,
                      80,
                      '42 %',
                      fgcolor=Display.WHITE,
                      bdcolor=Display.BLACK)
    mtemp = Meter(wri,
                  25,
                  2,
                  height=70,
                  divisions=5,
                  ptcolor=Display.YELLOW,
                  label='temperature',
                  style=Meter.BAR,
                  legends=('0', '10', '20', '30', '40', '50'))

    mhumi = Meter(wri,
                  25,
                  80,
                  height=70,
                  divisions=5,
                  ptcolor=Display.YELLOW,
                  label='humidity',
                  style=Meter.BAR,
                  legends=('0', '20', '40', '60', '80', '100'))

    steps = 11

    for i in range(steps):
        tempC, humi = sht30.getTempAndHumi(clockStretching=SHT3X.CLOCK_STRETCH,
                                           repeatability=SHT3X.REP_S_HIGH)
        #print("Temperature: ",tempC,"°C, Humidity: ",humi,"%")
        humiText = "{0:.1f} %".format(humi)
        tempText = "{0:.1f} deg C".format(tempC)
        t = tempC / 50.0
        h = humi / 100.0
        mtemp.value(t)
        mhumi.value(h)
        tempLabel.value(tempText)
        humiLabel.value(humiText)

        #print(humiText)
        refresh(st7735)
        utime.sleep(1)
    refresh(st7735)
示例#8
0
def vari_fields():
    print('Variable label styles.')
    refresh(st7735, True)  # Clear any prior image
    wri_large = CWriter(st7735, freesans20, GREEN, BLACK, verbose=False)
    wri_large.set_clip(True, True, False)
    Label(wri_large, 0, 0, 'Text')
    Label(wri_large, 20, 0, 'Border')
    width = wri_large.stringlen('Yellow')
    lbl_text = Label(wri_large, 0, 65, width)
    lbl_bord = Label(wri_large, 20, 65, width)
    lbl_text.value('Red')
    lbl_bord.value('Red')
    lbl_var = Label(wri_large, 50, 2, '25.46', fgcolor=RED, bdcolor=RED)
    refresh(st7735)
    utime.sleep(2)
    lbl_text.value('Red')
    lbl_bord.value('Yellow')
    lbl_var.value(bdcolor=YELLOW)
    refresh(st7735)
    utime.sleep(2)
    lbl_text.value('Red')
    lbl_bord.value('None')
    lbl_var.value(bdcolor=False)
    refresh(st7735)
    utime.sleep(2)
    lbl_text.value('Yellow')
    lbl_bord.value('None')
    lbl_var.value(fgcolor=YELLOW)
    refresh(st7735)
    utime.sleep(2)
    lbl_text.value('Blue')
    lbl_bord.value('Green')
    lbl_var.value('18.99', fgcolor=BLUE, bdcolor=GREEN)
    Label(wri, st7735.height - wri.height - 2, 0, 'Done', fgcolor=RED)
    refresh(st7735)
示例#9
0
def vari_fields():
    print('vari_fields')
    refresh(st7735, True)  # Clear any prior image
    Label(wri, 0, 0, 'Text:')
    Label(wri, 20, 0, 'Border:')
    width = wri.stringlen('Yellow')
    lbl_text = Label(wri, 0, 40, width)
    lbl_bord = Label(wri, 20, 40, width)
    lbl_text.value('Red')
    lbl_bord.value('Red')
    lbl_var = Label(wri, 40, 2, '25.46', fgcolor=RED, bdcolor=RED)
    refresh(st7735)
    utime.sleep(2)
    lbl_text.value('Red')
    lbl_bord.value('Yellow')
    lbl_var.value(bdcolor=YELLOW)
    refresh(st7735)
    utime.sleep(2)
    lbl_text.value('Red')
    lbl_bord.value('None')
    lbl_var.value(bdcolor=False)
    refresh(st7735)
    utime.sleep(2)
    lbl_text.value('Yellow')
    lbl_bord.value('None')
    lbl_var.value(fgcolor=YELLOW)
    refresh(st7735)
    utime.sleep(2)
    lbl_text.value('Blue')
    lbl_bord.value('Green')
    lbl_var.value('18.99', fgcolor=BLUE, bdcolor=GREEN)
    refresh(st7735)