예제 #1
0
def test():
    st7735.clear()
    rhs = st7735.size()[0] - 1
    print("rhs: ", rhs)
    st7735.line(rhs - 20, 0, rhs, 20, Display.WHITE)
    square_side = 10
    st7735.fill_rect(rhs - square_side, 0, square_side, square_side,
                     Display.BLUE)

    wri = CWriter(st7735, freesans20)
    wri.setcolor(Display.GREEN, Display.BLACK)
    wri.set_textpos(st7735, 0, 0)  # verbose = False to suppress console output
    wri.printstring('Sunday\n')
    wri.printstring('12 Aug 2018\n')
    wri.printstring('10.30am')
    st7735.show()
예제 #2
0
    async def run(self, pir, ssd):
        # Define colors
        white = ssd.rgb(255, 255, 255)
        black = ssd.rgb(0, 0, 0)
        red = ssd.rgb(255, 0, 0)
        blue = ssd.rgb(0, 0, 255)
        yellow = ssd.rgb(255, 255, 0)
        green = ssd.rgb(0, 255, 0)

        # Instantiate CWriters
        wri_l = CWriter(ssd, font, green, black, self.verbose)  # Large font.
        wri_s = CWriter(ssd, arial10, white, black, self.verbose)  # Small text

        # Instantiate interpolator and draw the scale
        interp = Interpolator(pir)
        self.draw_scale(ssd)

        while True:
            t = ticks_ms()  # For verbose timing
            self.mapper.set_range(self.tmin, self.tmax)
            interp.refresh()  # Acquire data
            max_t = -1000
            min_t = 1000
            sum_t = 0
            for row in range(32):
                for col in range(32):
                    # Transpose, reflect and invert
                    val = interp((31 - col) / 31, row / 31)
                    max_t = max(max_t, val)
                    min_t = min(min_t, val)
                    sum_t += val
                    ssd.rect(col * 2, row * 2, 2, 2,
                             ssd.rgb(*self.mapper(val)))
                await asyncio.sleep(0)
            self.avg = round(sum_t / 1024)
            if self.mode == _AUTO:
                self.tmin = round(min_t)
                self.tmax = round(max_t)
            if self.rf_disp:
                if self.rf_txt:
                    wri_l.set_textpos(ssd, 66, 0)
                    wri_l.printstring('Max:{:+4d}C\n'.format(int(max_t)))
                    wri_l.printstring('Min:{:+4d}C\n'.format(int(min_t)))
                    wri_l.printstring('Avg:{:+4d}C'.format(self.avg))
                    wri_s.set_textpos(ssd, 128 - arial10.height(), 64)
                    wri_s.setcolor(yellow, black)
                    wri_s.printstring('Chip:{:5.1f}C'.format(
                        pir.temperature()))
                    wri_s.set_textpos(ssd, 0, 90)
                    wri_s.setcolor(red, black)
                    wri_s.printstring('{:4d}C '.format(self.tmax))
                    wri_s.set_textpos(ssd, 28, 95)
                    wri_s.setcolor(green, black)
                    if self.mode == _HOG:
                        wri_s.printstring('Hog  ')
                    elif self.mode == _NORM:
                        wri_s.printstring('Norm  ')
                    else:
                        wri_s.printstring('Auto  ')
                    wri_s.set_textpos(ssd, 64 - arial10.height(), 90)
                    wri_s.setcolor(blue, black)
                    wri_s.printstring('{:4d}C '.format(self.tmin))
                    self.rf_txt = False
                ssd.show()
            self.verbose and print(ticks_diff(ticks_ms(), t))
            gc.collect()