Closed d3monlalov closed 2 months ago
Thanks, all ok with СWriter, I have a good result!!! Some problems left with setup color because it value is not answer RGB565 format, but it's not so important for me
For color you need to use the
CWriter
class -Writer
is for monochrome displays.CWriter
is documented here with a usage example.An alternative approach is to use nan-gui which uses a
Label
class to provide for text objects whose contents and colors may be dynamically updated..
Im just read documentation about CWriter and begin understand what I did wrong with color settings, thanks
Hi! Im trying to use your driver for TFT ST7735 LCD and ESR32-Wroom. All right, but i dont understand how I can to change a color of text in printstring function My code below `from machine import Pin, I2C,SPI from ina219 import INA219 from logging import INFO from ST7735 import TFT from font import terminalfont import time from framebuf import FrameBuffer, RGB565 from writer import Writer import freesans20 import courier20
buf = bytearray(1601282) fb = FrameBuffer(buf, 160, 128, RGB565)
spi = SPI(2, baudrate=30000000, polarity=0, phase=0, sck=Pin(18), mosi=Pin(23), miso=Pin(12)) tft=TFT(spi,2,4,5) tft.initr() tft.rgb(True) tft._setwindowloc((0,0),(159,127)) tft.rotation(1) tft.fill(TFT.BLACK)
i2c = I2C(1, scl = Pin(22), sda = Pin(21))
def init_ina(): SHUNT_OHMS = 0.1 global ina ina = INA219(SHUNT_OHMS, i2c)#, log_level=INFO) ina.configure()
def i2c_scan():
init_ina() i2c_scan() old_voltage = 0 old_time = 0
class NotionalDisplay(FrameBuffer): def init(self, width, height, buffer): self.width = width self.height = height self.buffer = buffer self.mode = RGB565 super().init(self.buffer, self.width, self.height, self.mode)
my_display = NotionalDisplay(160, 128, fb) wri = Writer(my_display, freesans20)
while True: new_time = time.ticks_ms() new_voltage = ina.voltage() if (new_time - old_time) >1000 or abs(new_voltage-old_voltage)>0.05: fb.fill(0x0000) fgcolor = 56 Writer.set_textpos(my_display, 20, 10) Writer.setcolor() wri.printstring("{0:.3f}".format(new_voltage))
fb.text(("{0:.3f}".format(new_voltage)),50,50,TFT.BLUE)