epd_2in7_test.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #!/usr/bin/python
  2. # -*- coding:utf-8 -*-
  3. import sys
  4. sys.path.append(r'../lib')
  5. import epd2in7
  6. import epdconfig
  7. import time
  8. from PIL import Image,ImageDraw,ImageFont
  9. import traceback
  10. try:
  11. print("epd2in7 Demo")
  12. epd = epd2in7.EPD()
  13. print("init and Clear")
  14. epd.init()
  15. epd.Clear(0xFF)
  16. font24 = ImageFont.truetype('../lib/Font.ttc', 24)
  17. font18 = ImageFont.truetype('../lib/Font.ttc', 18)
  18. # Drawing on the Horizontal image
  19. print("1.Drawing on the Horizontal image...")
  20. Himage = Image.new('1', (epd.height, epd.width), 255) # 255: clear the frame
  21. draw = ImageDraw.Draw(Himage)
  22. draw.text((10, 0), 'hello world', font = font24, fill = 0)
  23. draw.text((150, 0), u'微雪电子', font = font24, fill = 0)
  24. draw.line((20, 50, 70, 100), fill = 0)
  25. draw.line((70, 50, 20, 100), fill = 0)
  26. draw.rectangle((20, 50, 70, 100), outline = 0)
  27. draw.line((165, 50, 165, 100), fill = 0)
  28. draw.line((140, 75, 190, 75), fill = 0)
  29. draw.arc((140, 50, 190, 100), 0, 360, fill = 0)
  30. draw.rectangle((80, 50, 130, 100), fill = 0)
  31. draw.chord((200, 50, 250, 100), 0, 360, fill = 0)
  32. epd.display(epd.getbuffer(Himage))
  33. time.sleep(2)
  34. # Drawing on the Vertical image
  35. print("2.Drawing on the Vertical image...")
  36. Limage = Image.new('1', (epd.width, epd.height), 255) # 255: clear the frame
  37. draw = ImageDraw.Draw(Limage)
  38. draw.text((2, 0), 'hello world', font = font18, fill = 0)
  39. draw.text((20, 50), u'微雪电子', font = font18, fill = 0)
  40. draw.line((10, 90, 60, 140), fill = 0)
  41. draw.line((60, 90, 10, 140), fill = 0)
  42. draw.rectangle((10, 90, 60, 140), outline = 0)
  43. draw.line((95, 90, 95, 140), fill = 0)
  44. draw.line((70, 115, 120, 115), fill = 0)
  45. draw.arc((70, 90, 120, 140), 0, 360, fill = 0)
  46. draw.rectangle((10, 150, 60, 200), fill = 0)
  47. draw.chord((70, 150, 120, 200), 0, 360, fill = 0)
  48. epd.display(epd.getbuffer(Limage))
  49. time.sleep(2)
  50. print("3.read bmp file")
  51. Himage = Image.open('../pic/2in7.bmp')
  52. epd.display(epd.getbuffer(Himage))
  53. time.sleep(2)
  54. print("4.read bmp file on window")
  55. Himage2 = Image.new('1', (epd.height, epd.width), 255) # 255: clear the frame
  56. bmp = Image.open('../pic/100x100.bmp')
  57. Himage2.paste(bmp, (50,10))
  58. epd.display(epd.getbuffer(Himage2))
  59. time.sleep(2)
  60. print("Clear...")
  61. epd.Clear(0xFF)
  62. print("Goto Sleep...")
  63. epd.sleep()
  64. except IOError as e:
  65. print(e)
  66. except KeyboardInterrupt:
  67. print("ctrl + c:")
  68. epdconfig.module_exit()
  69. exit()