立即注册

扫一扫,访问微社区

micropython-microbit 中文社区

查看: 140|回复: 0

micropython驱动微雪2.13寸墨水屏(电子纸)

[复制链接]
  • TA的每日心情
    开心
    2019-5-12 11:06
  • 签到天数: 8 天

    [LV.3]偶尔看看II

    发表于 2019-4-23 11:15:19 | 显示全部楼层 |阅读模式

    马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

    您需要 登录 才可以下载或查看,没有帐号?立即注册

    x
    原帖:https://forum.micropython.org/viewtopic.php?t=6319&p=35965


                                   
    登录/注册后可看大图



    1. """
    2.         Example for 2.13 inch black & white & red Waveshare 2.13B E-ink screen
    3.         Run on ESP32 Waveshare driver board (software SPI)
    4.         Adapted by me -- April 2019
    5. """

    6. import epaper2in13b
    7. from machine import Pin, SPI

    8. # software SPI on ESP32 Waveshare driver board
    9. sck = Pin(13)
    10. mosi = Pin(14)
    11. cs = Pin(15)
    12. busy = Pin(25)
    13. rst = Pin(26)
    14. dc = Pin(27)
    15. # miso is not used but must be declared. Let's take any unused gpio: 12
    16. miso = Pin(12)
    17. spi = SPI(baudrate=100000, polarity=0, phase=0, sck=sck, mosi=mosi, miso=miso)

    18. e = epaper2in13b.EPD(spi, cs, dc, rst, busy)
    19. e.init()

    20. w = 104
    21. h = 212
    22. x = 0
    23. y = 0

    24. # --------------------

    25. # use a frame buffer
    26. # 212 * 104 / 8 = 2756 - that's some pixels
    27. import framebuf
    28. buf = bytearray(w * h // 8)
    29. fb = framebuf.FrameBuffer(buf, w, h, framebuf.MONO_HLSB)
    30. black = 0
    31. white = 1
    32. fb.fill(white)

    33. # --------------------

    34. # write hello world with black bg and white text

    35. # from toto import hello_world_dark

    36. from image_dark import hello_world_dark
    37. from image_light import hello_world_light
    38. print('Image dark')
    39. bufImage = hello_world_dark
    40. fbImage = framebuf.FrameBuffer(bufImage, 128, 296, framebuf.MONO_HLSB)
    41. fb.blit(fbImage, 20, 2)
    42. bufImage = hello_world_light
    43. fbImage = framebuf.FrameBuffer(bufImage, 128, 296, framebuf.MONO_HLSB)
    44. fb.blit(fbImage, 168, 2)
    45. # e.display_frame(buf)
    46. e.display_frame(buf, buf)

    47. # --------------------

    48. # write hello world with white bg and black text
    49. print('Image light')
    50. #e.display_frame(hello_world_light)

    51. # --------------------


    52. print('Frame buffer things')
    53. fb.fill(white)
    54. fb.text('Hello World',30,0,black)
    55. fb.pixel(30, 10, black)
    56. fb.hline(30, 30, 10, black)
    57. fb.vline(30, 50, 10, black)
    58. fb.line(30, 70, 40, 80, black)
    59. fb.rect(30, 90, 10, 10, black)
    60. fb.fill_rect(30, 110, 10, 10, black)
    61. for row in range(0,36):
    62.         fb.text(str(row),0,row*8,black)
    63. fb.text('Line 36',0,288,black)
    64. #e.display_frame(buf)
    65. e.display_frame(buf, buf)

    66. # --------------------

    67. # wrap text inside a box
    68. black = 0
    69. white = 1
    70. # clear
    71. fb.fill(white)
    72. # display as much as this as fits in the box
    73. str = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam vel neque in elit tristique vulputate at et dui. Maecenas nec felis lectus. Pellentesque sit amet facilisis dui. Maecenas ac arcu euismod, tempor massa quis, ultricies est.'

    74. # this could be useful as a new method in FrameBuffer
    75. def text_wrap(str,x,y,color,w,h,border=None):
    76.         # optional box border
    77.         if border is not None:
    78.                 fb.rect(x, y, w, h, border)
    79.         cols = w // 8
    80.         # for each row
    81.         j = 0
    82.         for i in range(0, len(str), cols):
    83.                 # draw as many chars fit on the line
    84.                 fb.text(str[i:i+cols], x, y + j, color)
    85.                 j += 8
    86.                 # dont overflow text outside the box
    87.                 if j >= h:
    88.                         break

    89. # clear
    90. fb.fill(white)

    91. # draw text box 1
    92. # box position and dimensions
    93. print('Box 1')
    94. bx = 8
    95. by = 8
    96. bw = 112 #  = 14 cols
    97. bh = 112 #  = 14 rows (196 chars in total)
    98. text_wrap(str,bx,by,black,bw,bh,black)
    99. #e.display_frame(buf)
    100. e.display_frame(buf, buf)

    101. # draw text box 2
    102. print('Box 2 & 3')
    103. bx = 0
    104. by = 128
    105. bw = w # 128 = 16 cols
    106. bh = 6 * 8 # 48 = 6 rows (96 chars in total)
    107. text_wrap(str,bx,by,black,bw,bh,black)

    108. # draw text box 3
    109. bx = 0
    110. by = 184
    111. bw = w//2 # 64 = 8 cols
    112. bh = 8 * 8 # 64 = 8 rows (64 chars in total)
    113. text_wrap(str,bx,by,black,bw,bh,None)
    114. #e.display_frame(buf)
    115. e.display_frame(buf, buf)

    116. # --------------------
    复制代码



    手机扫码浏览
    回复

    使用道具 举报

    游客
    回复
    您需要登录后才可以回帖 登录 | 立即注册

    关闭

    站长推荐上一条 /3 下一条

    Archiver|手机版|小黑屋|micropython-microbit 中文社区 ( 鄂ICP备17012469号 )

    GMT+8, 2019-5-22 17:10 , Processed in 0.114833 second(s), 21 queries .

    Powered by Discuz! X3.4

    © 2001-2013 Comsenz Inc.

    快速回复 返回顶部 返回列表