epd_1in54_V2_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_V2
  6. import epdconfig
  7. import time
  8. from PIL import Image,ImageDraw,ImageFont
  9. import traceback
  10. try:
  11. print("epd1in54_V2 Demo")
  12. epd = epd1in54_V2.EPD()
  13. print("init and Clear")
  14. epd.init()
  15. epd.Clear(0xFF)
  16. time.sleep(1)
  17. # Drawing on the image
  18. print("1.Drawing on the image...")
  19. image = Image.new('1', (epd.width, epd.height), 255) # 255: clear the frame
  20. draw = ImageDraw.Draw(image)
  21. font = ImageFont.truetype('../lib/Font.ttc', 24)
  22. draw.rectangle((0, 10, 200, 34), fill = 0)
  23. draw.text((8, 12), 'hello world', font = font, fill = 255)
  24. draw.text((8, 36), u'微雪电子', font = font, fill = 0)
  25. draw.line((16, 60, 56, 60), fill = 0)
  26. draw.line((56, 60, 56, 110), fill = 0)
  27. draw.line((16, 110, 56, 110), fill = 0)
  28. draw.line((16, 110, 16, 60), fill = 0)
  29. draw.line((16, 60, 56, 110), fill = 0)
  30. draw.line((56, 60, 16, 110), fill = 0)
  31. draw.arc((90, 60, 150, 120), 0, 360, fill = 0)
  32. draw.rectangle((16, 130, 56, 180), fill = 0)
  33. draw.chord((90, 130, 150, 190), 0, 360, fill = 0)
  34. epd.display(epd.getbuffer(image.rotate(90)))
  35. time.sleep(2)
  36. # read bmp file
  37. print("2.read bmp file...")
  38. image = Image.open('../pic/1in54.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.width, epd.height), 255) # 255: clear the frame
  45. bmp = Image.open('../pic/100x100.bmp')
  46. image1.paste(bmp, (50,50))
  47. epd.display(epd.getbuffer(image1))
  48. time.sleep(2)
  49. # partial update
  50. print("4.show time...")
  51. time_image = Image.new('1', (epd.width, epd.height), 255)
  52. epd.displayPartBaseImage(epd.getbuffer(time_image))
  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.displayPart(epd.getbuffer(time_image))
  61. num = num + 1
  62. if(num == 10):
  63. break
  64. print("Clear...")
  65. epd.init()
  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()