示例#1
0
def main():
    tft = st7789.ST7789(SPI(1, baudrate=30000000, sck=Pin(18), mosi=Pin(19)),
                        135,
                        240,
                        reset=Pin(23, Pin.OUT),
                        cs=Pin(5, Pin.OUT),
                        dc=Pin(16, Pin.OUT),
                        backlight=Pin(4, Pin.OUT),
                        rotation=3)

    tft.init()

    while True:
        for rotation in range(4):
            tft.rotation(rotation)
            tft.fill(0)
            col_max = tft.width() - font.WIDTH * 6
            row_max = tft.height() - font.HEIGHT

            for _ in range(128):
                tft.text(
                    font, "Hello!", random.randint(0, col_max),
                    random.randint(0, row_max),
                    st7789.color565(random.getrandbits(8),
                                    random.getrandbits(8),
                                    random.getrandbits(8)),
                    st7789.color565(random.getrandbits(8),
                                    random.getrandbits(8),
                                    random.getrandbits(8)))
示例#2
0
def main():
    tft.init()

    tft.fill(st7789.RED)
    center("Hello!")
    utime.sleep(2)
    tft.fill(st7789.BLACK)

    while True:
        for rotation in range(4):
            tft.rotation(rotation)
            tft.fill(0)
            col_max = tft.width() - font.WIDTH*6
            row_max = tft.height() - font.HEIGHT

            for _ in range(128):
                tft.text(
                    font,
                    "Hello!",
                    random.randint(0, col_max),
                    random.randint(0, row_max),
                    st7789.color565(
                        random.getrandbits(8),
                        random.getrandbits(8),
                        random.getrandbits(8)),
                    st7789.color565(
                        random.getrandbits(8),
                        random.getrandbits(8),
                        random.getrandbits(8)))
示例#3
0
def main():
    tft = st7789.ST7789(SPI(1,
                            SPI.MASTER,
                            baudrate=30000000,
                            polarity=1,
                            phase=0),
                        240,
                        320,
                        reset=Pin('X3', Pin.OUT),
                        cs=Pin('X5', Pin.OUT),
                        dc=Pin('X4', Pin.OUT),
                        backlight=Pin('X2', Pin.OUT),
                        rotation=3)

    tft.init()

    while True:
        for rotation in range(4):
            tft.rotation(rotation)
            tft.fill(0)
            col_max = tft.width() - font.WIDTH * 6
            row_max = tft.height() - font.HEIGHT

            for _ in range(250):
                tft.text(
                    font, "Hello!", random.randint(0, col_max),
                    random.randint(0, row_max),
                    st7789.color565(random.getrandbits(8),
                                    random.getrandbits(8),
                                    random.getrandbits(8)),
                    st7789.color565(random.getrandbits(8),
                                    random.getrandbits(8),
                                    random.getrandbits(8)))
示例#4
0
def tft_micrologo():
    tft.fill(0)
    tft.jpg('logo.jpg', 0, 0, 1)
    tft.text(
        font,
        " MICROPYTHON ",
        int(tft.width() / 2 - 105), int(tft.height() - 18),
        st.color565(255, 255, 255),
        st.color565(1, 1, 1)
    )
示例#5
0
def wheel(pos):
    pos = 255 - (pos % 255)
    if pos < 85:
        return st7789.color565(255 - pos * 3, 0, pos * 3)

    if pos < 170:
        pos -= 85
        return st7789.color565(0, pos * 3, 255 - pos * 3)

    pos -= 170
    return st7789.color565(pos * 3, 255 - pos * 3, 0)
示例#6
0
def color_wheel(WheelPos):
    """returns a 565 color from the given position of the color wheel"""
    WheelPos = (255 - WheelPos) % 255

    if WheelPos < 85:
        return st7789.color565(255 - WheelPos * 3, 0, WheelPos * 3)

    if WheelPos < 170:
        WheelPos -= 85
        return st7789.color565(0, WheelPos * 3, 255 - WheelPos * 3)

    WheelPos -= 170
    return st7789.color565(WheelPos * 3, 255 - WheelPos * 3, 0)
示例#7
0
def color_wheel(position):
    """returns a 565 color from the given position of the color wheel"""
    position = (255 - position) % 255

    if position < 85:
        return st7789.color565(255 - position * 3, 0, position * 3)

    if position < 170:
        position -= 85
        return st7789.color565(0, position * 3, 255 - position * 3)

    position -= 170
    return st7789.color565(position * 3, 255 - position * 3, 0)
def fill_vline():
    display._set_mem_access_mode(0, False, False, False)
    for i in range(0, 135):
        display.vline(
            i, 0, 110,
            st7789.color565(random.getrandbits(8), random.getrandbits(8),
                            random.getrandbits(8)))

    display._set_mem_access_mode(2, False, False, False)
    for i in range(0, 135):
        display.vline(
            i, 0, 110,
            st7789.color565(random.getrandbits(8), random.getrandbits(8),
                            random.getrandbits(8)))

    clear_screen()
def fill_hline():
    display._set_mem_access_mode(0, False, False, False)
    for i in range(0, 240):
        display.hline(
            0, i, 65,
            st7789.color565(random.getrandbits(8), random.getrandbits(8),
                            random.getrandbits(8)))

    display._set_mem_access_mode(1, False, False, False)
    for i in range(0, 240):
        display.hline(
            0, i, 65,
            st7789.color565(random.getrandbits(8), random.getrandbits(8),
                            random.getrandbits(8)))

    clear_screen()
示例#10
0
 def draw(self) -> None:
     """
     Clock
     This function takes a time object and
     draws an analogue clock onto the screen
     in UTC time.
     Arg:
         t: The time object from the utime lib
     Returns: 
         None
     """
     display.fill(display.color565((255, 255, 255)))
     # tft.circle(Center, 63, TFT.GRAY)
     h, m, s = self.convTime(time.localtime())
     self.hand(h, 40, (64, 64), display.color565((0, 0, 0)))
     self.hand(m, 20, (64, 64), display.color565((150, 150, 150)))
     self.hand(s, 50, (64, 64), display.color565((0, 255, 0)))
 def draw():
     display.draw_text(0, 0, 'Arcade Pix 9x11', arcadepix, color565(255, 0, 0))
     display.draw_text(0, 12, 'Bally 7x9', bally, color565(0, 255, 0))
     display.draw_text(0, 23, 'Broadway', broadway, color565(0, 0, 255))
     display.draw_text(0, 36, 'Espresso', espresso_dolce,
                       color565(0, 255, 255))
     display.draw_text(0, 64, 'Fixed Font 5x8', fixed_font,
                       color565(255, 0, 255))
     display.draw_text(0, 76, 'Neato 5x7', neato, color565(255, 255, 0))
     display.draw_text(0, 85, 'Robotron 7x11', robotron,
                       color565(255, 255, 255))
     display.draw_text(0, 96, 'Unispace', unispace, color565(255, 128, 0))
     display.draw_text(0, 120, 'Wendy 7x8', wendy, color565(255, 0, 128))
     sleep(2)
示例#12
0
class Color:
    black = st7789.color565(0, 0, 0)
    white = st7789.color565(255, 255, 255)
    grey = st7789.color565(44, 44, 44)
    red = st7789.color565(255, 0, 0)
    green = st7789.color565(0, 200, 0)
    yellow = st7789.color565(200, 200, 0)
    blue = st7789.color565(0, 0, 255)
def test():
    """Test code."""
    # Baud rate of 14500000 seems about the max
    BL_Pin = 4  #backlight pin
    SCLK_Pin = 18  #clock pin
    MOSI_Pin = 19  #mosi pin
    MISO_Pin = 2  #miso pin
    RESET_Pin = 23  #reset pin
    DC_Pin = 16  #data/command pin
    CS_Pin = 5  #chip select pin

    Button1_Pin = 35
    #right button
    Button2_Pin = 0
    #left button
    button1 = Pin(Button1_Pin, Pin.IN, Pin.PULL_UP)
    button2 = Pin(Button2_Pin, Pin.IN, Pin.PULL_UP)

    BLK = Pin(BL_Pin, Pin.OUT)
    spi = SPI(baudrate=40000000,
              miso=Pin(MISO_Pin),
              mosi=Pin(MOSI_Pin, Pin.OUT),
              sck=Pin(SCLK_Pin, Pin.OUT))
    display = ST7789(spi, 135, 240, cs=Pin(CS_Pin), dc=Pin(DC_Pin), rst=None)
    display.fill(0)

    x, y = 0, 0
    angle = 0.0
    #  Loop all angles from 0 to 2 * PI radians
    while angle < PI2:
        # Calculate x, y from a vector with known length and angle
        x = int(CENTER_X * sin(angle) + HALF_WIDTH)
        y = int(CENTER_Y * cos(angle) + HALF_HEIGHT)
        color = color565(*hsv_to_rgb(angle / PI2, 1, 1))
        display.line(x, y, CENTER_X, CENTER_Y, color)
        angle += ANGLE_STEP_SIZE

    for r in range(CENTER_X, 0, -1):
        color = color565(*hsv_to_rgb(r / HALF_WIDTH, 1, 1))
        display.fill_circle(CENTER_X, CENTER_Y, r, color)

    display.fill(0)
示例#14
0
 def draw(self):
     """
     docstring
     """
     self.display.draw_text(0,
                            0,
                            'Booting UI',
                            self.unispace,
                            color565(255, 32, 64),
                            landscape=False)
     sleep(2)
示例#15
0
 def display_result(self, text):
     print("Display Result")
     self.tft.fill(0)
     
     self.tft.text( font, text["line1"], 0, 0, st7789.color565(255,255,255), st7789.color565(0,0,0))
     self.tft.text( font, text["line2"], 0, 20, st7789.color565(255,255,255), st7789.color565(0,0,0))
     self.tft.text( font, text["line3"], 0, 40, st7789.color565(255,255,255), st7789.color565(0,0,0))
     
     color = colormap[text["code"]]
     self.tft.fill_rect(180,80,50,50, color)
示例#16
0
def test():
    """Test code."""
    # Baud rate of 14500000 seems about the max
    BLK = Pin(BL_Pin, Pin.OUT)
    spi = SPI(baudrate=40000000, miso=Pin(MISO_Pin), mosi=Pin(MOSI_Pin, Pin.OUT), sck=Pin(SCLK_Pin, Pin.OUT))
    display = ST7789(spi, 135, 240, cs=Pin(CS_Pin), dc=Pin(DC_Pin), rst=None)
    BLK.value(1)

    c = 0
    for x in range(0, 128, 16):
        for y in range(0, 240, 16):
            color = color565(*hsv_to_rgb(c / 64, 1, 1))
            display.fill_circle(x + 8, y + 7, 7, color)
            c += 1
    sleep(9)
    display.cleanup()
示例#17
0
def main():
    spi = machine.SPI(1, baudrate=40000000, polarity=1)
    display = st7789.ST7789(
        spi,
        240,
        240,
        reset=machine.Pin(5, machine.Pin.OUT),
        dc=machine.Pin(2, machine.Pin.OUT),
    )
    display.init_display()

    while True:
        display.fill(
            st7789.color565(
                random.getrandbits(8),
                random.getrandbits(8),
                random.getrandbits(8),
            ), )
        # Pause 2 seconds.
        time.sleep(2)
示例#18
0
def test():
    """Bouncing box."""
    try:
        # Baud rate of 14500000 seems about the max
        BL_Pin = 4     #backlight pin
        SCLK_Pin = 18  #clock pin
        MOSI_Pin = 19  #mosi pin
        MISO_Pin = 2   #miso pin
        RESET_Pin = 23 #reset pin
        DC_Pin = 16    #data/command pin
        CS_Pin = 5     #chip select pin

        Button1_Pin = 35; #right button
        Button2_Pin = 0;  #left button
        button1 = Pin(Button1_Pin, Pin.IN, Pin.PULL_UP)
        button2 = Pin(Button2_Pin, Pin.IN, Pin.PULL_UP)

        BLK = Pin(BL_Pin, Pin.OUT)
        spi = SPI(baudrate=40000000, miso=Pin(MISO_Pin), mosi=Pin(MOSI_Pin, Pin.OUT), sck=Pin(SCLK_Pin, Pin.OUT))
        display = ST7789(spi, 135, 240, cs=Pin(CS_Pin), dc=Pin(DC_Pin), rst=None)
        display.fill(0)

        colors = [color565(255, 0, 0),
                  color565(0, 255, 0),
                  color565(0, 0, 255),
                  color565(255, 255, 0),
                  color565(0, 255, 255),
                  color565(255, 0, 255)]
        sizes = [12, 11, 10, 9, 8, 7]
        boxes = [Box(135, 240, sizes[i], display,
                 colors[i]) for i in range(6)]

        while True:
            timer = ticks_us()
            for b in boxes:
                b.update_pos()
                b.draw()
            # Attempt to set framerate to 30 FPS
            timer_dif = 33333 - ticks_diff(ticks_us(), timer)
            if timer_dif > 0:
                sleep_us(timer_dif)

    except KeyboardInterrupt:
        display.cleanup()
示例#19
0
from machine import Pin, ADC, I2C, SoftSPI, PWM
from time import sleep_ms
import machine
import gc
import random
from st7789 import ST7789, color565
from time import sleep_ms

spi = SoftSPI(baudrate=10000000,
              polarity=1,
              phase=0,
              sck=Pin(10, Pin.OUT),
              mosi=Pin(11, Pin.OUT),
              miso=Pin(8))  #sck=D0, mosi=D1

display = ST7789(spi,
                 reset=Pin(12, Pin.OUT),
                 dc=Pin(13, Pin.OUT),
                 cs=Pin(9, Pin.OUT),
                 backlight=Pin(14, Pin.OUT),
                 rotation=0)

display.fill(0)
display.rect(0, 0, 240, 280, color565(255, 0, 0))
#display.text( "ABCD", 50, 50, color=(255,255,255), background=(0,0,0))
示例#20
0
def random_color():
    return st7789.color565(random.getrandbits(8), random.getrandbits(8),
                           random.getrandbits(8))
示例#21
0
BACKLIGHT_PIN = 10
RESET_PIN = 11
DC_PIN = 12
CS_PIN = 13
CLK_PIN = 14
DIN_PIN = 15  # lower left corner

import st7789

import vga1_bold_16x32 as font

spi = SPI(1, baudrate=31250000, sck=Pin(CLK_PIN), mosi=Pin(DIN_PIN))
tft = st7789.ST7789(spi,
                    240,
                    320,
                    reset=Pin(RESET_PIN, Pin.OUT),
                    cs=Pin(CS_PIN, Pin.OUT),
                    dc=Pin(DC_PIN, Pin.OUT),
                    backlight=Pin(BACKLIGHT_PIN, Pin.OUT),
                    rotation=3)
tft.init()

tft.text(font, "Hello World!", 10, 0, st7789.color565(255, 255, 255),
         st7789.color565(0, 0, 0))
tft.text(font, "Hello World!", 10, 50, st7789.color565(255, 0, 0),
         st7789.color565(0, 0, 0))
tft.text(font, "Hello World!", 10, 100, st7789.color565(0, 255, 0),
         st7789.color565(0, 0, 0))
tft.text(font, "Hello World!", 10, 150, st7789.color565(0, 0, 255),
         st7789.color565(0, 0, 0))
示例#22
0
from machine import SPI, Pin
import st7789
import vga2_bold_16x32 as font
import random

print('Booting')
spi = SPI(2, baudrate=30000000, polarity=1, phase=1, sck=Pin(18), mosi=Pin(19))
#machine.SPI(2, baudrate=40000000, polarity=1, sck=machine.Pin(18), mosi=machine.Pin(19))
display = st7789.ST7789(spi,
                        240,
                        240,
                        reset=Pin(23, Pin.OUT),
                        cs=Pin(5, Pin.OUT),
                        dc=Pin(27, Pin.OUT),
                        backlight=Pin(12, Pin.OUT),
                        rotation=0)
display.init()
display.fill(st7789.color565(5, 5, 5))
display.text(
    font, 'KungFOO rocks!', 50, 50,
    st7789.color565(random.getrandbits(8), random.getrandbits(8),
                    random.getrandbits(8)),
    st7789.color565(random.getrandbits(8), random.getrandbits(8),
                    random.getrandbits(8)))
def test():

    rot = 0
    """Test code."""
    BL_Pin = 4     #backlight pin
    SCLK_Pin = 18  #clock pin
    MOSI_Pin = 19  #mosi pin
    MISO_Pin = 2   #miso pin
    RESET_Pin = 23 #reset pin
    DC_Pin = 16    #data/command pin
    CS_Pin = 5     #chip select pin

    Button1_Pin = 35; #right button
    Button2_Pin = 0;  #left button
    button1 = Pin(Button1_Pin, Pin.IN, Pin.PULL_UP)
    button2 = Pin(Button2_Pin, Pin.IN, Pin.PULL_UP)

    BLK = Pin(BL_Pin, Pin.OUT)
    BLK.value(1)
    spi = SPI(baudrate=40000000, miso=Pin(MISO_Pin), mosi=Pin(MOSI_Pin, Pin.OUT), sck=Pin(SCLK_Pin, Pin.OUT))
    display = ST7789(spi, 135, 240, cs=Pin(CS_Pin), dc=Pin(DC_Pin), rst=None)
    display.fill(0)

    def cls():
        display.fill(0)
        display.pixel(10,10,color565(0, 255, 0))

    def draw():
        display.draw_text(0, 0, 'Arcade Pix 9x11', arcadepix, color565(255, 0, 0))
        display.draw_text(0, 12, 'Bally 7x9', bally, color565(0, 255, 0))
        display.draw_text(0, 23, 'Broadway', broadway, color565(0, 0, 255))
        display.draw_text(0, 36, 'Espresso', espresso_dolce,
                          color565(0, 255, 255))
        display.draw_text(0, 64, 'Fixed Font 5x8', fixed_font,
                          color565(255, 0, 255))
        display.draw_text(0, 76, 'Neato 5x7', neato, color565(255, 255, 0))
        display.draw_text(0, 85, 'Robotron 7x11', robotron,
                          color565(255, 255, 255))
        display.draw_text(0, 96, 'Unispace', unispace, color565(255, 128, 0))
        display.draw_text(0, 120, 'Wendy 7x8', wendy, color565(255, 0, 128))
        sleep(2)


    arcadepix = XglcdFont('fonts/ArcadePix9x11.c', 9, 11)
    bally = XglcdFont('fonts/Bally7x9.c', 7, 9)
    broadway = XglcdFont('fonts/Broadway17x15.c', 17, 15)
    espresso_dolce = XglcdFont('fonts/EspressoDolce18x24.c', 18, 24)
    fixed_font = XglcdFont('fonts/FixedFont5x8.c', 5, 8)
    neato = XglcdFont('fonts/Neato5x7.c', 5, 7, letter_count=223)
    robotron = XglcdFont('fonts/Robotron7x11.c', 7, 11)
    unispace = XglcdFont('fonts/Unispace12x24.c', 12, 24)
    wendy = XglcdFont('fonts/Wendy7x8.c', 7, 8)

    while True:

      cls()
      draw()


      sleep(1)

      cls()
      display.draw_text(0, 127, 'Arcade Pix 9x11', arcadepix,
                        color565(255, 0, 0),
                        landscape=True)
      display.draw_text(12, 127, 'Bally 7x9', bally, color565(0, 255, 0),
                        landscape=True)
      display.draw_text(23, 127, 'Broadway', broadway, color565(0, 0, 255),
                        landscape=True)
      display.draw_text(36, 127, 'Espresso', espresso_dolce,
                        color565(0, 255, 255), landscape=True)
      display.draw_text(64, 127, 'Fixed Font 5x8', fixed_font,
                        color565(255, 0, 255), landscape=True)
      display.draw_text(76, 127, 'Neato 5x7', neato, color565(255, 255, 0),
                        landscape=True)
      display.draw_text(85, 127, 'Robotron 7x11', robotron,
                        color565(255, 255, 255),
                        landscape=True)
      display.draw_text(96, 127, 'Unispace', unispace, color565(255, 128, 0),
                        landscape=True)
      display.draw_text(120, 127, 'Wendy 7x8', wendy, color565(255, 0, 128),
                        landscape=True)

      sleep(1)
      display.fill(0)
      display.fill(color565(0, 0, 255))
      display.fill(0)

      display.draw_text(0, 0, 'Arcade Pix 9x11', arcadepix, color565(255, 0, 0),
                        background=color565(0, 255, 255))
      display.draw_text(0, 12, 'Bally 7x9', bally, color565(0, 255, 0),
                        background=color565(0, 0, 128))
      display.draw_text(0, 23, 'Broadway', broadway, color565(0, 0, 255),
                        background=color565(255, 255, 0))
      display.draw_text(0, 36, 'Espresso', espresso_dolce,
                        color565(0, 255, 255), background=color565(255, 0, 0))
      display.draw_text(0, 64, 'Fixed Font 5x8', fixed_font,
                        color565(255, 0, 255), background=color565(0, 128, 0))
      display.draw_text(0, 76, 'Neato 5x7', neato, color565(255, 255, 0),
                        background=color565(0, 0, 255))
      display.draw_text(0, 85, 'Robotron 7x11', robotron,
                        color565(255, 255, 255),
                        background=color565(128, 128, 128))
      display.draw_text(0, 96, 'Unispace', unispace, color565(255, 128, 0),
                        background=color565(0, 128, 255))
      display.draw_text(0, 120, 'Wendy 7x8', wendy, color565(255, 0, 128),
                        background=color565(255, 255, 255))

      sleep(1)
示例#24
0
from micropython import const
from machine import Pin, Timer, ADC, SPI
#from hardware.button import Button
from hardware.aswitch import Pushbutton as Button
from hardware.basehardware import BaseHardware
from hardware.blescanner import BLEScanner

import st7789 
import utime
import vga1_8x16 as font
BUTTON_A_PIN = const(35)
#BUTTON_B_PIN = const(0)
BATT_PIN = const(34)

colormap = {
    "PINK": st7789.color565(255, 128, 192),
    "ORANGE" : st7789.color565(255,128,64),
    "GREY" : st7789.color565(127, 127, 127),
    "TURQUOISE" : st7789.color565(0, 128, 128),
    "AZURE" : st7789.color565(0, 128, 255),
    "OLIVE" : st7789.color565(128, 128, 0),
    "PURPLE" : st7789.color565(128, 0, 128),
    "WHITE" : st7789.color565(255, 255, 255)
}
#


class Hardware(BaseHardware):
    
    def __init__(self, config) :
        self.config = config
 def cls():
     display.fill(0)
     display.pixel(10,10,color565(0, 255, 0))
示例#26
0
 def draw(self) -> None:
     display.fill_rect(*self.pos, *self.size, display.color565(self.color))
示例#27
0
spi = machine.SPI(2,
                  baudrate=30000000,
                  polarity=1,
                  phase=1,
                  sck=machine.Pin(18),
                  mosi=machine.Pin(19))

display = st7789.ST7789(spi,
                        135,
                        240,
                        reset=machine.Pin(23, machine.Pin.OUT),
                        cs=machine.Pin(5, machine.Pin.OUT),
                        dc=machine.Pin(16, machine.Pin.OUT))

display.init()
display.fill(st7789.BLACK)

row = 0
again = True
while again:
    color = st7789.color565(random.getrandbits(8), random.getrandbits(8),
                            random.getrandbits(8))

    row += 32

    pytext.text(display, pick_item(fonts), "Hello!", row, 0, color)

    if row > 192:
        display.fill(st7789.BLACK)
        row = 0
示例#28
0
 def cls(self):
     """
     docstring
     """
     self.display.fill(0)
     self.display.pixel(10, 10, color565(0, 255, 0))
示例#29
0
from machine import Pin, SPI
import st7789
from oled7segment import *
import vga1_16x32 as font
#import NotoSansMono_32 as font

WIDTH = const(240)
HEIGHT = const(135)
ROTATION = const(1)

BLACK = st7789.BLACK
BLUE = st7789.BLUE
CYAN = st7789.CYAN
GREEN = st7789.GREEN
MAGENTA = st7789.MAGENTA
ORANGE = st7789.color565(255,165,0)
RED = st7789.RED
WHITE = st7789.WHITE
YELLOW = st7789.YELLOW

BG_COLOR = BLACK
COLOR = WHITE

#from loggerconfig import *

my_hostname = "PowerControlOne"
my_device_id = "SmokerOne"

MINIMUM_PULSE_WIDTH_MS = 2000

INITIAL_POWER_LEVEL = 0.0