pyb.LCD.rst 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. .. currentmodule:: pyb
  2. .. _pyb.LCD:
  3. class LCD -- LCD control for the LCD touch-sensor pyskin
  4. ========================================================
  5. The LCD class is used to control the LCD on the LCD touch-sensor pyskin,
  6. LCD32MKv1.0. The LCD is a 128x32 pixel monochrome screen, part NHD-C12832A1Z.
  7. The pyskin must be connected in either the X or Y positions, and then
  8. an LCD object is made using::
  9. lcd = pyb.LCD('X') # if pyskin is in the X position
  10. lcd = pyb.LCD('Y') # if pyskin is in the Y position
  11. Then you can use::
  12. lcd.light(True) # turn the backlight on
  13. lcd.write('Hello world!\n') # print text to the screen
  14. This driver implements a double buffer for setting/getting pixels.
  15. For example, to make a bouncing dot, try::
  16. x = y = 0
  17. dx = dy = 1
  18. while True:
  19. # update the dot's position
  20. x += dx
  21. y += dy
  22. # make the dot bounce of the edges of the screen
  23. if x <= 0 or x >= 127: dx = -dx
  24. if y <= 0 or y >= 31: dy = -dy
  25. lcd.fill(0) # clear the buffer
  26. lcd.pixel(x, y, 1) # draw the dot
  27. lcd.show() # show the buffer
  28. pyb.delay(50) # pause for 50ms
  29. Constructors
  30. ------------
  31. .. class:: pyb.LCD(skin_position)
  32. Construct an LCD object in the given skin position. ``skin_position`` can be 'X' or 'Y', and
  33. should match the position where the LCD pyskin is plugged in.
  34. Methods
  35. -------
  36. .. method:: LCD.command(instr_data, buf)
  37. Send an arbitrary command to the LCD. Pass 0 for ``instr_data`` to send an
  38. instruction, otherwise pass 1 to send data. ``buf`` is a buffer with the
  39. instructions/data to send.
  40. .. method:: LCD.contrast(value)
  41. Set the contrast of the LCD. Valid values are between 0 and 47.
  42. .. method:: LCD.fill(colour)
  43. Fill the screen with the given colour (0 or 1 for white or black).
  44. This method writes to the hidden buffer. Use ``show()`` to show the buffer.
  45. .. method:: LCD.get(x, y)
  46. Get the pixel at the position ``(x, y)``. Returns 0 or 1.
  47. This method reads from the visible buffer.
  48. .. method:: LCD.light(value)
  49. Turn the backlight on/off. True or 1 turns it on, False or 0 turns it off.
  50. .. method:: LCD.pixel(x, y, colour)
  51. Set the pixel at ``(x, y)`` to the given colour (0 or 1).
  52. This method writes to the hidden buffer. Use ``show()`` to show the buffer.
  53. .. method:: LCD.show()
  54. Show the hidden buffer on the screen.
  55. .. method:: LCD.text(str, x, y, colour)
  56. Draw the given text to the position ``(x, y)`` using the given colour (0 or 1).
  57. This method writes to the hidden buffer. Use ``show()`` to show the buffer.
  58. .. method:: LCD.write(str)
  59. Write the string ``str`` to the screen. It will appear immediately.