Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Enlarged Text demo on SSD1306 OLED display
- # Tony Goodhew (Tonygo2) 5 July 2026
- # Method:
- # Draws normal characters in 'scratch area'
- # at bottom of screen. Then enlarges it
- # at the required position. Small text is then
- # removed. Avoid bottom 8 lines of screen until
- # the end of screen drawing.
- from machine import Pin,I2C
- from ssd1306 import SSD1306_I2C
- i2c = I2C(sda=0,scl=1)
- #Set up OLED display
- WIDTH = 128 # oled display width
- HEIGHT = 64
- oled = SSD1306_I2C(WIDTH,HEIGHT,i2c)
- oled.fill(0)
- oled.show()
- # Procedure to draw enlarged text on SSD1306
- # using the built-in font
- def xtext(string,xx,yy,size):
- ln = len(string)
- oled.text(string,0,56,1) # Normal size string
- for yq in range(8):
- for xq in range(ln*8):
- px = oled.pixel(0+xq,56+yq) # Get pixel value
- if px == 1:
- oled.rect(xx+xq*size,yy+yq*size,size,size,1,1)
- oled.rect(0,56,ln*8,8,0,1) # Clear temp text area
- xtext("Tony",17,7,3)
- xtext("0123456",8,40,2)
- oled.rect(0,0,128,64,1)
- oled.show()
Advertisement
Add Comment
Please, Sign In to add comment