epd_2in13_test.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #!/usr/bin/python
  2. # -*- coding:utf-8 -*-
  3. import sys
  4. sys.path.append(r'../lib')
  5. import epd2in13
  6. import epdconfig
  7. import time
  8. from PIL import Image,ImageDraw,ImageFont
  9. import traceback
  10. try:
  11. print("epd2in13 Demo")
  12. epd = epd2in13.EPD()
  13. print("init and Clear")
  14. epd.init(epd.lut_full_update)
  15. epd.Clear(0xFF)
  16. # Drawing on the image
  17. font15 = ImageFont.truetype('../lib/Font.ttc', 15)
  18. font24 = ImageFont.truetype('../lib/Font.ttc', 24)
  19. print("1.Drawing on the image...")
  20. image = Image.new('1', (epd.height, epd.width), 255) # 255: clear the frame
  21. draw = ImageDraw.Draw(image)
  22. draw.rectangle([(0,0),(50,50)],outline = 0)
  23. draw.rectangle([(55,0),(100,50)],fill = 0)
  24. draw.line([(0,0),(50,50)], fill = 0,width = 1)
  25. draw.line([(0,50),(50,0)], fill = 0,width = 1)
  26. draw.chord((10, 60, 50, 100), 0, 360, fill = 0)
  27. draw.ellipse((55, 60, 95, 100), outline = 0)
  28. draw.pieslice((55, 60, 95, 100), 90, 180, outline = 0)
  29. draw.pieslice((55, 60, 95, 100), 270, 360, fill = 0)
  30. draw.polygon([(110,0),(110,50),(150,25)],outline = 0)
  31. draw.polygon([(190,0),(190,50),(150,25)],fill = 0)
  32. draw.text((120, 60), 'e-Paper demo', font = font15, fill = 0)
  33. draw.text((110, 90), u'微雪电子', font = font24, fill = 0)
  34. epd.display(epd.getbuffer(image))
  35. time.sleep(2)
  36. # read bmp file
  37. print("2.read bmp file...")
  38. image = Image.open('../pic/2in13.bmp')
  39. epd.display(epd.getbuffer(image))
  40. time.sleep(2)
  41. # read bmp file on window
  42. print("3.read bmp file on window...")
  43. # epd.Clear(0xFF)
  44. image1 = Image.new('1', (epd.height, epd.width), 255) # 255: clear the frame
  45. bmp = Image.open('../pic/100x100.bmp')
  46. image1.paste(bmp, (2,2))
  47. epd.display(epd.getbuffer(image1))
  48. time.sleep(2)
  49. # # partial update
  50. print("4.show time...")
  51. epd.init(epd.lut_partial_update)
  52. epd.Clear(0xFF)
  53. time_image = Image.new('1', (epd.height, epd.width), 255)
  54. time_draw = ImageDraw.Draw(time_image)
  55. num = 0
  56. while (True):
  57. time_draw.rectangle((120, 80, 220, 105), fill = 255)
  58. time_draw.text((120, 80), time.strftime('%H:%M:%S'), font = font24, fill = 0)
  59. epd.display(epd.getbuffer(time_image))
  60. num = num + 1
  61. if(num == 10):
  62. break
  63. print("Clear...")
  64. epd.init(epd.lut_full_update)
  65. epd.Clear(0xFF)
  66. print("Goto Sleep...")
  67. epd.sleep()
  68. except IOError as e:
  69. print(e)
  70. except KeyboardInterrupt:
  71. print("ctrl + c:")
  72. epdconfig.module_exit()
  73. exit()