Exemple #1
0
def meter():
    print('Meter test.')
    refresh(st7735, True)  # Clear any prior image
    color = lambda v: RED if v > 0.7 else YELLOW if v > 0.5 else GREEN
    txt = lambda v: 'ovr' if v > 0.7 else 'high' if v > 0.5 else 'ok'
    m0 = Meter(wri,
               5,
               2,
               divisions=4,
               ptcolor=YELLOW,
               label='left',
               style=Meter.BAR,
               legends=('0.0', '0.5', '1.0'))
    l0 = LED(wri,
             st7735.height - 16 - wri.height,
             2,
             bdcolor=YELLOW,
             label='over')
    m1 = Meter(wri,
               5,
               50,
               divisions=4,
               ptcolor=YELLOW,
               label='right',
               style=Meter.BAR,
               legends=('0.0', '0.5', '1.0'))
    l1 = LED(wri,
             st7735.height - 16 - wri.height,
             50,
             bdcolor=YELLOW,
             label='over')
    m2 = Meter(wri,
               5,
               98,
               divisions=4,
               ptcolor=YELLOW,
               label='bass',
               style=Meter.BAR,
               legends=('0.0', '0.5', '1.0'))
    l2 = LED(wri,
             st7735.height - 16 - wri.height,
             98,
             bdcolor=YELLOW,
             label='over')
    steps = 10
    for n in range(steps):
        v = int.from_bytes(uos.urandom(3), 'little') / 16777216
        m0.value(v, color(v))
        l0.color(color(v))
        l0.text(txt(v), fgcolor=color(v))
        v = n / steps
        m1.value(v, color(v))
        l1.color(color(v))
        l1.text(txt(v), fgcolor=color(v))
        v = 1 - n / steps
        m2.value(v, color(v))
        l2.color(color(v))
        l2.text(txt(v), fgcolor=color(v))
        refresh(st7735)
        utime.sleep(1)
Exemple #2
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
def cart():
    print('Cartesian data test.')

    def populate_1(func):
        x = -1
        while x < 1.01:
            yield x, func(x)  # x, y
            x += 0.1

    def populate_2():
        x = -1
        while x < 1.01:
            yield x, x**2  # x, y
            x += 0.1

    refresh(ssd, True)  # Clear any prior image
    g = CartesianGraph(wri,
                       2,
                       2,
                       yorigin=2,
                       fgcolor=WHITE,
                       gridcolor=LIGHTGREEN)  # Asymmetric y axis
    curve1 = Curve(g, YELLOW,
                   populate_1(lambda x: x**3 + x**2 - x, ))  # args demo
    curve2 = Curve(g, RED, populate_2())
    refresh(ssd)
Exemple #4
0
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)
Exemple #5
0
def meter():
    
    print('Meter test.')
    refresh(st7735, True)  # Clear any prior image
#     FOR TEMPERATURE
    color_temp = lambda v : RED if v > 40 else YELLOW if v > 27 else GREEN
    m0 = Meter(wri, 5, 12, height=60, divisions = 5, ptcolor=BLUE,
              label='temp', style=Meter.BAR, legends=('0', '10', '20', '30', '40', '50'))
    l0 = LED(wri, st7735.height - 46 - wri.height, 12, bdcolor=YELLOW, label ='0')

#     FOR HUMIDITY
#     color_humid = lambda v : RED if v > 0.8 else YELLOW if v > 0.6 else GREEN
    m1 = Meter(wri, 5, 80, height=60, divisions = 5, ptcolor=YELLOW,
              label='right', style=Meter.BAR, legends=('0', '20', '40', '60', '80', '100'))
    l1 = LED(wri, st7735.height - 46 - wri.height, 80, bdcolor=YELLOW, label ='0')

    sensor = SHT3X()
    # print(sensor.isPresent())
    
    while True:
        temp, humid = sensor.getTempAndHumi()
        print("Temporature:", temp, 'ºC, RH:', humid, '%')

        l0.text(str(temp)[:4])
        l1.text(str(humid)[:4])

        mtemp = temp / 50
        mhumid = humid / 100
        m0.value(mtemp, color_temp(temp))
        m1.value(mhumid)

        refresh(st7735)
        utime.sleep(1)
def rt_polar():
    print('Simulate realtime polar data acquisition.')
    refresh(ssd, True)  # Clear any prior image
    g = PolarGraph(wri, 2, 2, fgcolor=WHITE, gridcolor=LIGHTGREEN)
    curvey = PolarCurve(g, YELLOW)
    curver = PolarCurve(g, RED)
    for x in range(100):
        curvey.point(cmath.rect(x / 100, -x * cmath.pi / 30))
        curver.point(cmath.rect((100 - x) / 100, -x * cmath.pi / 30))
        utime.sleep_ms(60)
        refresh(ssd)
Exemple #7
0
async def meter(n, x, text, t):
    print('Meter {} test.'.format(n))
    m = Meter(wri, 5, x, divisions = 4, ptcolor=YELLOW,
              label=text, style=Meter.BAR, legends=('0.0', '0.5', '1.0'))
    l = LED(wri, ssd.height - 16 - wri.height, x, bdcolor=YELLOW, label ='over')
    while True:
        v = int.from_bytes(uos.urandom(3),'little')/16777216
        m.value(v, color(v))
        l.color(color(v))
        l.text(txt(v), fgcolor=color(v))
        refresh(ssd)
        await asyncio.sleep_ms(t)
def liss():
    print('Lissajous figure.')

    def populate():
        t = -math.pi
        while t <= math.pi:
            yield math.sin(t), math.cos(3 * t)  # x, y
            t += 0.1

    refresh(ssd, True)  # Clear any prior image
    g = CartesianGraph(wri, 2, 2, fgcolor=WHITE, gridcolor=LIGHTGREEN)
    curve = Curve(g, YELLOW, populate())
    refresh(ssd)
def polar_clip():
    print('Test of polar data clipping.')

    def populate(rot):
        f = lambda theta: cmath.rect(1.15 * math.sin(5 * theta), theta
                                     ) * rot  # complex
        nmax = 150
        for n in range(nmax + 1):
            yield f(2 * cmath.pi * n / nmax)  # complex z

    refresh(ssd, True)  # Clear any prior image
    g = PolarGraph(wri, 2, 2, fgcolor=WHITE, gridcolor=LIGHTGREEN)
    curve = PolarCurve(g, YELLOW, populate(1))
    curve1 = PolarCurve(g, RED, populate(cmath.rect(1, cmath.pi / 5), ))
    refresh(ssd)
def polar():
    print('Polar data test.')

    def populate():
        def f(theta):
            return cmath.rect(math.sin(3 * theta), theta)  # complex

        nmax = 150
        for n in range(nmax + 1):
            yield f(2 * cmath.pi * n / nmax)  # complex z

    refresh(ssd, True)  # Clear any prior image
    g = PolarGraph(wri, 2, 2, fgcolor=WHITE, gridcolor=LIGHTGREEN)
    curve = PolarCurve(g, YELLOW, populate())
    refresh(ssd)
Exemple #11
0
def meter(use_spi=False, soft=True):
    ssd = setup(use_spi, soft)
    wri = Writer(ssd, arial10, verbose=False)
    ssd.fill(0)
    refresh(ssd)
    m0 = Meter(wri, 5, 2, height = 50, divisions = 4, legends=('0.0', '0.5', '1.0'))
    m1 = Meter(wri, 5, 44, height = 50, divisions = 4, legends=('-1', '0', '+1'))
    m2 = Meter(wri, 5, 86, height = 50, divisions = 4, legends=('-1', '0', '+1'))
    steps = 10
    for n in range(steps + 1):
        m0.value(int.from_bytes(uos.urandom(3),'little')/16777216)
        m1.value(n/steps)
        m2.value(1 - n/steps)
        refresh(ssd)
        utime.sleep(1)
Exemple #12
0
 def draw_screen(self, n=None):
     if n is None:
         n = self.cur_scr
     sobjs = self.scr_objs[n]
     if n != self.cur_scr:
         # draw static objects only when screen is changed
         refresh(self.vg.oled, True)  # clear screen
         self.lbl_status.show(True)
         for sobj in sobjs:
             sobj.show(True)
         self.cur_scr = n
         return
     # draw dynamic objects every cycle
     for sobj in sobjs:
         sobj.show(False)
     refresh(self.vg.oled)
Exemple #13
0
def compass(x):
    print('Compass test.')
    refresh(st7735, 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(st7735)
Exemple #14
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)
def seq():
    print('Time sequence test - sine and cosine.')
    refresh(ssd, True)  # Clear any prior image
    # y axis at t==now, no border
    g = CartesianGraph(wri,
                       2,
                       2,
                       xorigin=10,
                       fgcolor=WHITE,
                       gridcolor=LIGHTGREEN,
                       bdcolor=False)
    tsy = TSequence(g, YELLOW, 50)
    tsr = TSequence(g, RED, 50)
    for t in range(100):
        g.clear()
        tsy.add(0.9 * math.sin(t / 10))
        tsr.add(0.4 * math.cos(t / 10))
        refresh(ssd)
        utime.sleep_ms(100)
Exemple #16
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')
async def main(loop):
    print('Press Pyboard usr button to stop test.')
    bar = asyn.Barrier(4, refresh, (ssd,))
    # Asynchronously flash Pyboard LED's. Because we can.
    loop.create_task(asyn.Cancellable(flash, 1, 200)())
    loop.create_task(asyn.Cancellable(flash, 2, 233)())
    # Task for each meter and GUI LED
    loop.create_task(asyn.Cancellable(meter, bar,  2, 'left')())
    loop.create_task(asyn.Cancellable(meter, bar, 50, 'right')())
    loop.create_task(asyn.Cancellable(meter, bar, 98, 'bass')())
    try:
        while True:
            await asyncio.sleep_ms(800)
            # If necessary wait until all meters have updated.
            # Barrier callback updates display.
            await bar
    except asyn.StopTask:
        ssd.fill(0)  # Clear display at end.
        refresh(ssd)
Exemple #18
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 lem():
    print('Lemniscate of Bernoulli.')

    def populate():
        t = -math.pi
        while t <= math.pi + 0.1:
            x = 0.5 * math.sqrt(2) * math.cos(t) / (math.sin(t)**2 + 1)
            y = math.sqrt(2) * math.cos(t) * math.sin(t) / (math.sin(t)**2 + 1)
            yield x, y
            t += 0.1

    refresh(ssd, True)  # Clear any prior image
    Label(wri, 82, 2, 'To infinity and beyond...')
    g = CartesianGraph(wri,
                       2,
                       2,
                       height=75,
                       fgcolor=WHITE,
                       gridcolor=LIGHTGREEN)
    curve = Curve(g, YELLOW, populate())
    refresh(ssd)
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)
Exemple #21
0
def multi_fields(t):
    print('Dynamic labels.')
    refresh(st7735, True)  # Clear any prior image
    nfields = []
    dy = wri.height + 6
    y = 2
    col = 15
    width = wri.stringlen('99.99')
    for txt in ('X:', 'Y:', 'Z:'):
        Label(wri, y, 0, txt)  # Use wri default colors
        nfields.append(Label(wri, y, col, width,
                             bdcolor=None))  # Specify a border, color TBD
        y += dy

    end = utime.ticks_add(utime.ticks_ms(), t * 1000)
    while utime.ticks_diff(end, utime.ticks_ms()) > 0:
        for field in nfields:
            value = int.from_bytes(uos.urandom(3), 'little') / 167772
            overrange = None if value < 70 else YELLOW if value < 90 else RED
            field.value('{:5.2f}'.format(value),
                        fgcolor=overrange,
                        bdcolor=overrange)
        refresh(st7735)
        utime.sleep(1)
    Label(wri, 0, 64, ' OK ', True, fgcolor=RED)
    refresh(st7735)
    utime.sleep(1)
Exemple #22
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)
Exemple #23
0
def meter():
    print('meter')
    refresh(st7735, True)  # Clear any prior image
    mtemp = Meter(wri,
                  5,
                  2,
                  height=100,
                  divisions=7,
                  ptcolor=YELLOW,
                  label='temperature',
                  style=Meter.BAR,
                  legends=('0', '5', '10', '20', '30', '40', '50'))

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

    steps = 10
    for _ in range(steps):
        v = int.from_bytes(uos.urandom(3), 'little') / 16777216
        mtemp.value(v)
        htemp.value(v)
        refresh(st7735)
        utime.sleep(1)
    refresh(st7735)
Exemple #24
0
def cart():
    print('Cartesian data test.')

    def populate_1():
        x = 0
        while x < 2.01:
            yield x, exp(-x) * cos(10 * x)  # x, y
            x += 0.1

    refresh(st7735, True)  # Clear any prior image
    g = CartesianGraph(wri,
                       20,
                       2,
                       fgcolor=Display.WHITE,
                       gridcolor=Display.LIGHT_GREEN)  # Asymmetric y axis
    curve1 = Curve(g, Display.RED, populate_1(), origin=(1, 0))
    title = Label(wri,
                  2,
                  10,
                  'Damped Oscillator',
                  fgcolor=Display.WHITE,
                  bdcolor=Display.WHITE)
    refresh(st7735)
Exemple #25
0
async def main():
    print('Press Pyboard usr button to stop test.')
    # Asynchronously flash Pyboard LED's. Because we can.
    leds = [
        asyncio.create_task(flash(1, 200)),
        asyncio.create_task(flash(2, 233))
    ]
    # Task for each meter and GUI LED
    mtasks = [
        MyMeter(2, 'left').task,
        MyMeter(50, 'right').task,
        MyMeter(98, 'bass').task
    ]
    k = Killer()
    while True:
        if await k.wait(800):  # Switch was pressed
            break
        refresh(ssd)
    for task in mtasks + leds:
        task.cancel()
    await asyncio.sleep_ms(0)
    ssd.fill(0)  # Clear display at end.
    refresh(ssd)
Exemple #26
0
def voltmeter():
    print('Voltmeter with ADC connected to pin 34')
    refresh(st7735, True)  # Clear any prior imag
    title = Label(wri,
                  2,
                  40,
                  'Voltmeter',
                  fgcolor=Display.WHITE,
                  bdcolor=Display.WHITE)
    uv = lambda phi: cmath.rect(1, phi)  # Return a unit vector of phase phi

    scale = Scale(wri, 30, 5, height=60, ticks=5, bdcolor=None,
                  label=50)  # Border in fg color
    voltage = Pointer(scale)

    while True:
        v = adc.read() * 3.3 / 4096  # we have Vdd = 3.3 V and a 12 bit ADC
        voltage.value(
            (0 + 0.9j) * cmath.rect(1, cmath.pi / 2 - (v / 5) * cmath.pi),
            Display.RED)
        scale.text('voltage: {0:.1f} V'.format(v))
        refresh(st7735)
        utime.sleep_ms(100)  # a measurement everv 100 ms
Exemple #27
0
def multi_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, small, verbose=False)
    wri.set_clip(False, False, False)

    nfields = []
    dy = small.height() + 6
    y = 2
    col = 15
    width = wri.stringlen('99.99')
    for txt in ('X:', 'Y:', 'Z:'):
        Label(wri, y, 0, txt)
        nfields.append(Label(wri, y, col, width, bdcolor=None))  # Draw border
        y += dy

    for _ in range(10):
        for field in nfields:
            value = int.from_bytes(uos.urandom(3),'little')/167772
            field.value('{:5.2f}'.format(value))
        refresh(ssd)
        utime.sleep(1)
    Label(wri, 0, 64, ' DONE ', True)
    refresh(ssd)
def rt_rect():
    print('Simulate realtime data acquisition of discontinuous data.')
    refresh(ssd, True)  # Clear any prior image
    g = CartesianGraph(wri, 2, 2, fgcolor=WHITE, gridcolor=LIGHTGREEN)
    curve = Curve(g, RED)
    x = -1
    for _ in range(40):
        y = 0.1 / x if abs(x) > 0.05 else None  # Discontinuity
        curve.point(x, y)
        utime.sleep_ms(100)
        refresh(ssd)
        x += 0.05
    g.clear()
    curve = Curve(g, YELLOW)
    x = -1
    for _ in range(40):
        y = -0.1 / x if abs(x) > 0.05 else None  # Discontinuity
        curve.point(x, y)
        utime.sleep_ms(100)
        refresh(ssd)
        x += 0.05
Exemple #29
0
def meter():
    print('meter')
    refresh(st7735, True)  # Clear any prior image
    m = Meter(wri,
              5,
              2,
              height=45,
              divisions=4,
              ptcolor=YELLOW,
              label='level',
              style=Meter.BAR,
              legends=('0.0', '0.5', '1.0'))
    l = LED(wri, 5, 40, bdcolor=YELLOW, label='over')
    steps = 10
    for _ in range(steps):
        v = int.from_bytes(uos.urandom(3), 'little') / 16777216
        m.value(v)
        l.color(GREEN if v < 0.5 else RED)
        refresh(st7735)
        utime.sleep(1)
    refresh(st7735)
Exemple #30
0
    print('1.4 inch TFT screen test on ESP8266')
    SPI_CS = 16
    SPI_DC = 15
    spi = SPI(1)

elif sys.platform == 'esp32':
    print('1.4 inch TFT screen test on ESP32')
    sck = Pin(18)
    miso = Pin(19)
    mosi = Pin(23)
    SPI_CS = 26
    SPI_DC = 5
    spi = SPI(2, baudrate=32000000, sck=sck, mosi=mosi, miso=miso)

st7735 = Display(spi, SPI_CS, SPI_DC)
refresh(st7735)

GREEN = color565(0, 255, 0)
RED = color565(255, 0, 0)
BLUE = color565(0, 0, 255)
YELLOW = color565(255, 255, 0)
BLACK = 0

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)


def meter():
    print('meter')
    refresh(st7735, True)  # Clear any prior image