Advertisement
Guest User

Untitled

a guest
Aug 18th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.10 KB | None | 0 0
  1. import board
  2. from busio import I2C
  3. from adafruit_ssd1306 import SSD1306_I2C
  4. from time import sleep
  5. from digitalio import DigitalInOut, Direction, Pull
  6.  
  7. i2c = I2C(board.SCL, board.SDA)
  8. oled = SSD1306_I2C(128, 32, i2c)
  9.  
  10. button_A = DigitalInOut(board.D9)
  11. button_B = DigitalInOut(board.D6)
  12. button_C = DigitalInOut(board.D5)
  13.  
  14. button_A.direction = Direction.INPUT
  15. button_B.direction = Direction.INPUT
  16. button_C.direction = Direction.INPUT
  17.  
  18. button_A.pull = Pull.UP
  19. button_B.pull = Pull.UP
  20. button_C.pull = Pull.UP
  21.  
  22. def check_buttons():
  23. if button_A.value is False:
  24. return 'A'
  25. elif button_B.value is False:
  26. return'B'
  27. elif button_C.value is False:
  28. return 'C'
  29. else:
  30. return None
  31.  
  32. def wait_for_A():
  33. sleep(0.5)
  34. while check_buttons() is not 'A':
  35. pass
  36.  
  37. oled.fill(0)
  38. oled.text('Adafruit Feather', 0, 0, 1)
  39. oled.text('Program selector', 0, 8, 1)
  40. oled.text('Press A to continue', 0, 24, 1)
  41. oled.show()
  42.  
  43. wait_for_A()
  44.  
  45. oled.fill(0)
  46. oled.text('Instructions:', 0, 0, 1)
  47. oled.text('Use A and C to move', 0, 8, 1)
  48. oled.text('up and down.', 0, 16, 1)
  49. oled.text('Press A to continue', 0, 24, 1)
  50. oled.show()
  51.  
  52. wait_for_A()
  53.  
  54. oled.fill(0)
  55. oled.text('Instructions (cont.):', 0, 0, 1)
  56. oled.text('Press B to select a', 0, 8, 1)
  57. oled.text('program.', 0, 16, 1)
  58. oled.text('Press A to continue', 0, 24, 1)
  59. oled.show()
  60.  
  61. wait_for_A()
  62.  
  63. oled.fill(0)
  64. oled.text('Instructions (cont.):', 0, 0, 1)
  65. oled.text('At anytime you can', 0, 8, 1)
  66. oled.text('press reset to go...', 0, 16, 1)
  67. oled.text('Press A to continue', 0, 24, 1)
  68. oled.show()
  69.  
  70. wait_for_A()
  71.  
  72. oled.fill(0)
  73. oled.text('Instructions (cont.):', 0, 0, 1)
  74. oled.text('... back to the main', 0, 8, 1)
  75. oled.text('screen.', 0, 16, 1)
  76. oled.text('Press A to continue', 0, 24, 1)
  77. oled.show()
  78.  
  79. wait_for_A()
  80.  
  81. oled.fill(0)
  82. oled.text('Instructions (cont.):', 0, 0, 1)
  83. oled.text('The programs will', 0, 8, 1)
  84. oled.text('have there own...', 0, 16, 1)
  85. oled.text('Press A to continue', 0, 24, 1)
  86. oled.show()
  87.  
  88. wait_for_A()
  89.  
  90. oled.fill(0)
  91. oled.text('Instructions (cont.):', 0, 0, 1)
  92. oled.text('... instructions.', 0, 8, 1)
  93. oled.text('Press A to continue', 0, 16, 1)
  94. oled.text('to menu', 0, 24, 1)
  95. oled.show()
  96.  
  97. wait_for_A()
  98.  
  99. oled.fill(0)
  100. oled.show()
  101.  
  102. class Button(DigitalInOut):
  103. def __init__(self, name, pin, direction=Direction.INPUT, pull=Pull.UP):
  104. self.name = name
  105. super().__init__(pin)
  106. self.direction = direction
  107. self.pull = pull
  108.  
  109. def wait_for_press(self):
  110. while self.value:
  111. pass
  112.  
  113. names = ["A", "B", "C"]
  114. pins = [board.D9, board.D6, board.D5]
  115. buttons = {name: Button(name, pin) for name, pin in zip(names, pins)}
  116.  
  117. def print_page(oled, strings):
  118. oled.fill(0)
  119. for i, s in enumerate(strings):
  120. oled.text(s, 0, i * 8, 1)
  121. oled.show()
  122.  
  123. messages = [
  124. """
  125. Adafruit Feather
  126. Program selector
  127.  
  128. Press A to continue
  129. """,
  130. """
  131. Instructions:
  132. Use A and C to move
  133. up and down
  134. Press A to continue
  135. """,
  136. """
  137. Instructions (cont.):
  138. Press B to select a
  139. program.
  140. Press A to continue
  141. """,
  142. ...
  143. ]
  144.  
  145. for message in messages:
  146. print_page(oled, message.splitlines()[1:])
  147. buttons["A"].wait_for_press()
  148. oled.fill(0)
  149. oled.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement