Advertisement
nguyenhung1903

Untitled

Oct 3rd, 2021
384
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.99 KB | None | 0 0
  1. # import thư viện
  2. import time
  3. import Adafruit_SSD1306
  4. from PIL import Image
  5. from PIL import ImageDraw
  6. from PIL import ImageFont
  7.  
  8. """thiết lập cho màn hình oled (128x64), ở đây mọi người có thể thay đổi để hiển thị trên màn hình oled 128x32 """
  9. disp = Adafruit_SSD1306.SSD1306_128_64(rst=None, i2c_bus=1, gpio=1)
  10. disp.begin()
  11. disp.clear()
  12. disp.display()
  13. width = disp.width
  14. height = disp.height
  15. image = Image.new('1', (width, height))
  16. draw = ImageDraw.Draw(image)
  17. draw.rectangle((0,0,width,height), outline=0, fill=0)
  18. padding = -2
  19. top = padding
  20. bottom = height-padding
  21. x = 0
  22. font = ImageFont.load_default()
  23. draw.rectangle((0,0,width,height), outline=0, fill=0)
  24. """x: là tọa độ từ trái sang (vd ở đây x = 0) và top: là từ trên xuống (vd: top = 0) thì sẽ in ra dòng chữ ‘hello world!’ ở tọa độ (0,0) của màn màn hinh oled."""
  25. draw.text((x, top),"Hello world!",  font=font, fill=255)
  26. disp.image(image)
  27. disp.display()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement