Пример #1
0
    def callback(topic, msg):
        zz = json.loads(msg.decode('utf-8'))
        d.fill_rectangle(0, 0, 240, 320, 0)  # erase before writing new info
        d.draw_text(0, 0, zz.get('header', "No header"),
                    ili.color565(0, 255, 0))

        y = 0
        for line in zz.get('text', ["No text"]):
            lines = wrap(line, 26)
            for line in lines:
                y += 15
                d.draw_text(0, y, line, ili.color565(255, 255, 255))
Пример #2
0
    def callback(topic, msg):
        zz = json.loads(msg.decode('utf-8'))
        d.fill(0)
        d.draw_text(0, 0, zz.get('artist', '')[:28], ili.color565(255, 0, 0))

        title = wrap(zz.get('title', ''), 28)
        y = 0
        for line in title:
            y += 15  # was 20
            d.draw_text(0, y, line, ili.color565(0, 255, 0))

        lyrics = zz.get('lyrics', '')
        for line in lyrics:
            lines = wrap(line, 26)
            for line in lines:
                y += 15  # was 20
                if y > 305:
                    sleep(5)
                    d.fill(0)
                    d.draw_text(0, 0, title[0], ili.color565(0, 255, 0))
                    y = 15  # was 20

                d.draw_text(0, y, line, ili.color565(255, 255, 255))
Пример #3
0
from config import ssid, pw, topic
from config import mqtt_aws_host as host
import ili9341_text2 as ili
from umqtt_client_official import MQTTClient as umc

with open('mqtt_id', 'r') as f:
    mqtt_id = f.read().strip()

print("mqtt_id =", mqtt_id)
print("host =", host)

spi = machine.SPI(1, baudrate=32000000)
d = ili.ILI9341(spi, cs=machine.Pin(0), dc=machine.Pin(15))

d.fill(0)
d.draw_text(0, 0, "Hello Steve", ili.color565(255, 255, 255))

c = umc(mqtt_id, host, 1883)


def wrap(text, lim):
    lines = []
    pos = 0
    line = []
    for word in text.split():
        if pos + len(word) < lim + 1:
            line.append(word)
            pos += len(word) + 1
        else:
            lines.append(' '.join(line))
            line = [word]
Пример #4
0
'''
Can either be used by ampy or placed on esp8266 to test writing to the ili9341 with a larger font:
font2.py.  Also uses ili9341_text2.py and rgb_text2.py
'''

import machine
import ili9341_text2 as ili

spi = machine.SPI(1, baudrate=32000000)

display = ili.ILI9341(spi, cs=machine.Pin(0), dc=machine.Pin(15))
color = ((255, 0, 0), (0, 255, 0), (0, 0, 255), (255, 255, 0), (0, 255, 255),
         (255, 0, 255), (255, 255, 255), (255, 0, 0), (0, 255, 0), (0, 0, 255),
         (255, 255, 0), (0, 255, 255), (255, 0, 255), (255, 255, 255),
         (255, 0, 0), (0, 255, 0))
display.fill(0)
for x, y in enumerate(range(0, 310, 20)):
    display.draw_text(10, y, "Micropython Rocks " + str(y),
                      ili.color565(*color[x]))