epd_1in54c_test.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #!/usr/bin/python
  2. # -*- coding:utf-8 -*-
  3. import sys
  4. sys.path.append(r'../lib')
  5. import epd1in54c
  6. import epdconfig
  7. import time
  8. from PIL import Image,ImageDraw,ImageFont
  9. import traceback
  10. try:
  11. print("epd1in54c Demo")
  12. epd = epd1in54c.EPD()
  13. print("init and Clear")
  14. epd.init()
  15. epd.Clear()
  16. time.sleep(1)
  17. # Drawing on the image
  18. print("1.Drawing on the image...")
  19. blackimage = Image.new('1', (epd.width, epd.height), 255) # 255: clear the frame
  20. yellowimage = Image.new('1', (epd.width, epd.height), 255) # 255: clear the frame
  21. font = ImageFont.truetype('../lib/Font.ttc', 24)
  22. font18 = ImageFont.truetype('../lib/Font.ttc', 18)
  23. drawblack = ImageDraw.Draw(blackimage)
  24. drawyellow = ImageDraw.Draw(yellowimage)
  25. drawblack.rectangle((0, 10, 200, 34), fill = 0)
  26. drawblack.text((8, 12), 'hello world', font = font, fill = 255)
  27. drawblack.text((8, 36), u'微雪电子', font = font, fill = 0)
  28. drawblack.line((10, 100, 70, 100), fill = 0)
  29. drawblack.line((40, 70, 40, 130), fill = 0)
  30. drawyellow.rectangle((10, 70, 70, 130), outline = 0)
  31. drawyellow.arc((80, 70, 140, 130), 0, 360, fill = 0)
  32. drawyellow.chord((90, 80, 130, 120), 0, 360, fill = 0)
  33. epd.display(epd.getbuffer(blackimage),epd.getbuffer(yellowimage))
  34. time.sleep(1)
  35. # read bmp file
  36. print("2.read bmp file...")
  37. blackimage = Image.open('../pic/1in54c-b.bmp')
  38. yellowimage = Image.open('../pic/1in54c-y.bmp')
  39. epd.display(epd.getbuffer(blackimage),epd.getbuffer(yellowimage))
  40. time.sleep(1)
  41. # read bmp file on window
  42. print("3.read bmp file on window...")
  43. blackimage1 = Image.new('1', (epd.width, epd.height), 255) # 255: clear the frame
  44. yellowimage2 = Image.new('1', (epd.width, epd.height), 255)
  45. newimage = Image.open('../pic/100x100.bmp')
  46. blackimage1.paste(newimage, (50,50))
  47. epd.display(epd.getbuffer(blackimage1), epd.getbuffer(yellowimage2))
  48. print("Clear...")
  49. epd.init()
  50. epd.Clear()
  51. print("Goto Sleep...")
  52. epd.sleep()
  53. except IOError as e:
  54. print(e)
  55. except KeyboardInterrupt:
  56. print("ctrl + c:")
  57. epdconfig.module_exit()
  58. exit()