Skip to content

Long text with scale higher than 1 #37

@kwalkerk

Description

@kwalkerk

If text_scale is higher than 1 then assigning long text to a label for scrolling causes the text to not scroll all the way off the screen. This code is using a fixed string for the scrolling, so the MQTT message is not displayed, but the broker ip and the network ssid/password are required.

secrets = {
    'ssid' : **ENTER SSID**
    'password' :**ENTER PASSWORD",
    'timezone' : "America/New_York", # http://worldtimeapi.org/timezones,
    'mqtt_broker' :**ENTER MQTT BROKER IP**

    }

import time
import board
import terminalio
from adafruit_matrixportal.matrixportal import MatrixPortal
from adafruit_matrixportal.network import Network
import adafruit_minimqtt.adafruit_minimqtt as MQTT
import adafruit_esp32spi.adafruit_esp32spi_socket as socket
from secrets import secrets

# --- Display setup ---
matrixportal = MatrixPortal(status_neopixel=board.NEOPIXEL, debug=False)
network = matrixportal.network
network.connect()

mqtt = MQTT.MQTT(
    broker=secrets.get("mqtt_broker"),
    username=secrets.get("mqtt_user"),
    password=secrets.get("mqtt_password"),
    port=1883,
)

MQTT.set_socket(socket, network._wifi.esp)



matrixportal.add_text(
    text_font=terminalio.FONT,
    text_position=(0, (matrixportal.graphics.display.height // 2) - 1),
    text_scale = 1,
    scrolling=True,
    
    
)

SCROLL_DELAY = 0.04
UPDATE_DELAY = 2000
ourMessage = "Hark the Herald Angels Sing by an unknown choir"





def message_received(client, topic, message):
    global ourMessage
    print("Received {} for {}".format(message, topic))
    ourMessage=message

def subscribe():
    try:
        mqtt.is_connected()
    except MQTT.MMQTTException:
        mqtt.connect()
    mqtt.on_message = message_received
    mqtt.subscribe("frontporchmusic",1)
    

subscribe()



while True:
    # Set the red score text
    try:
        mqtt.is_connected()
        mqtt.loop()
    except (MQTT.MMQTTException, RuntimeError):
        network.connect()
        mqtt.reconnect()
        
    matrixportal.set_text(ourMessage, 0)
    
    matrixportal.scroll_text(SCROLL_DELAY)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions