main.py 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #!/usr/bin/python
  2. # -*- coding:utf-8 -*-
  3. import epd2in7
  4. import time
  5. from PIL import Image,ImageDraw,ImageFont
  6. import traceback
  7. try:
  8. epd = epd2in7.EPD()
  9. epd.init()
  10. epd.Clear(0xFF)
  11. # Drawing on the Horizontal image
  12. Himage = Image.new('1', (epd2in7.EPD_HEIGHT, epd2in7.EPD_WIDTH), 255) # 255: clear the frame
  13. # Drawing on the Vertical image
  14. Limage = Image.new('1', (epd2in7.EPD_WIDTH, epd2in7.EPD_HEIGHT), 255) # 255: clear the frame
  15. # Horizontal
  16. print("Drawing")
  17. draw = ImageDraw.Draw(Himage)
  18. font24 = ImageFont.truetype('/usr/share/fonts/truetype/wqy/wqy-microhei.ttc', 24)
  19. draw.text((10, 0), 'hello world', font = font24, fill = 0)
  20. draw.text((10, 20), '2.9inch e-Paper', font = font24, fill = 0)
  21. draw.text((150, 0), u'微雪电子', font = font24, fill = 0)
  22. draw.line((20, 50, 70, 100), fill = 0)
  23. draw.line((70, 50, 20, 100), fill = 0)
  24. draw.rectangle((20, 50, 70, 100), outline = 0)
  25. draw.line((165, 50, 165, 100), fill = 0)
  26. draw.line((140, 75, 190, 75), fill = 0)
  27. draw.arc((140, 50, 190, 100), 0, 360, fill = 0)
  28. draw.rectangle((80, 50, 130, 100), fill = 0)
  29. draw.chord((200, 50, 250, 100), 0, 360, fill = 0)
  30. epd.display(epd.getbuffer(Himage))
  31. time.sleep(2)
  32. # Vertical
  33. draw = ImageDraw.Draw(Limage)
  34. font18 = ImageFont.truetype('/usr/share/fonts/truetype/wqy/wqy-microhei.ttc', 18)
  35. draw.text((2, 0), 'hello world', font = font18, fill = 0)
  36. draw.text((2, 20), '2.9inch epd', font = font18, fill = 0)
  37. draw.text((20, 50), u'微雪电子', font = font18, fill = 0)
  38. draw.line((10, 90, 60, 140), fill = 0)
  39. draw.line((60, 90, 10, 140), fill = 0)
  40. draw.rectangle((10, 90, 60, 140), outline = 0)
  41. draw.line((95, 90, 95, 140), fill = 0)
  42. draw.line((70, 115, 120, 115), fill = 0)
  43. draw.arc((70, 90, 120, 140), 0, 360, fill = 0)
  44. draw.rectangle((10, 150, 60, 200), fill = 0)
  45. draw.chord((70, 150, 120, 200), 0, 360, fill = 0)
  46. epd.display(epd.getbuffer(Limage))
  47. time.sleep(2)
  48. print("read bmp file")
  49. Himage = Image.open('2in7.bmp')
  50. epd.display(epd.getbuffer(Himage))
  51. time.sleep(2)
  52. print("read bmp file on window")
  53. Himage2 = Image.new('1', (epd2in7.EPD_HEIGHT, epd2in7.EPD_WIDTH), 255) # 255: clear the frame
  54. bmp = Image.open('100x100.bmp')
  55. Himage2.paste(bmp, (50,10))
  56. epd.display(epd.getbuffer(Himage2))
  57. time.sleep(2)
  58. epd.sleep()
  59. except:
  60. print('traceback.format_exc():\n%s',traceback.format_exc())
  61. exit()