epd_1in54_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 epd1in54
  6. import epdconfig
  7. import time
  8. from PIL import Image,ImageDraw,ImageFont
  9. import traceback
  10. try:
  11. print("epd1in54 Demo")
  12. epd = epd1in54.EPD()
  13. print("init and Clear")
  14. epd.init(epd.lut_full_update)
  15. epd.Clear(0xFF)
  16. # Drawing on the image
  17. print("1.Drawing on the image...")
  18. image = Image.new('1', (epd.width, epd.height), 255) # 255: clear the frame
  19. draw = ImageDraw.Draw(image)
  20. font = ImageFont.truetype('../lib/Font.ttc', 24)
  21. draw.rectangle((0, 10, 200, 34), fill = 0)
  22. draw.text((8, 12), 'hello world', font = font, fill = 255)
  23. draw.text((8, 36), u'微雪电子', font = font, fill = 0)
  24. draw.line((16, 60, 56, 60), fill = 0)
  25. draw.line((56, 60, 56, 110), fill = 0)
  26. draw.line((16, 110, 56, 110), fill = 0)
  27. draw.line((16, 110, 16, 60), fill = 0)
  28. draw.line((16, 60, 56, 110), fill = 0)
  29. draw.line((56, 60, 16, 110), fill = 0)
  30. draw.arc((90, 60, 150, 120), 0, 360, fill = 0)
  31. draw.rectangle((16, 130, 56, 180), fill = 0)
  32. draw.chord((90, 130, 150, 190), 0, 360, fill = 0)
  33. epd.display(epd.getbuffer(image.rotate(90)))
  34. time.sleep(2)
  35. # read bmp file
  36. print("2.read bmp file...")
  37. image = Image.open('../pic/1in54.bmp')
  38. epd.display(epd.getbuffer(image))
  39. time.sleep(2)
  40. # read bmp file on window
  41. print("3.read bmp file on window...")
  42. epd.Clear(0xFF)
  43. image1 = Image.new('1', (epd.width, epd.height), 255) # 255: clear the frame
  44. bmp = Image.open('../pic/100x100.bmp')
  45. image1.paste(bmp, (50,50))
  46. epd.display(epd.getbuffer(image1))
  47. time.sleep(2)
  48. # # partial update
  49. print("4.show time...")
  50. epd.init(epd.lut_partial_update)
  51. epd.Clear(0xFF)
  52. time_image = Image.new('1', (epd.width, epd.height), 255)
  53. time_draw = ImageDraw.Draw(time_image)
  54. num = 0
  55. while (True):
  56. time_draw.rectangle((10, 10, 120, 50), fill = 255)
  57. time_draw.text((10, 10), time.strftime('%H:%M:%S'), font = font, fill = 0)
  58. newimage = time_image.crop([10, 10, 120, 50])
  59. time_image.paste(newimage, (10,10))
  60. epd.display(epd.getbuffer(time_image))
  61. num = num + 1
  62. if(num == 10):
  63. break
  64. print("Clear...")
  65. epd.init(epd.lut_full_update)
  66. epd.Clear(0xFF)
  67. print("Goto Sleep...")
  68. epd.sleep()
  69. except IOError as e:
  70. print(e)
  71. except KeyboardInterrupt:
  72. print("ctrl + c:")
  73. epdconfig.module_exit()
  74. exit()