Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import board
- from busio import I2C
- from adafruit_ssd1306 import SSD1306_I2C
- from time import sleep
- from digitalio import DigitalInOut, Direction, Pull
- i2c = I2C(board.SCL, board.SDA)
- oled = SSD1306_I2C(128, 32, i2c)
- button_A = DigitalInOut(board.D9)
- button_B = DigitalInOut(board.D6)
- button_C = DigitalInOut(board.D5)
- button_A.direction = Direction.INPUT
- button_B.direction = Direction.INPUT
- button_C.direction = Direction.INPUT
- button_A.pull = Pull.UP
- button_B.pull = Pull.UP
- button_C.pull = Pull.UP
- def check_buttons():
- if button_A.value is False:
- return 'A'
- elif button_B.value is False:
- return'B'
- elif button_C.value is False:
- return 'C'
- else:
- return None
- def wait_for_A():
- sleep(0.5)
- while check_buttons() is not 'A':
- pass
- oled.fill(0)
- oled.text('Adafruit Feather', 0, 0, 1)
- oled.text('Program selector', 0, 8, 1)
- oled.text('Press A to continue', 0, 24, 1)
- oled.show()
- wait_for_A()
- oled.fill(0)
- oled.text('Instructions:', 0, 0, 1)
- oled.text('Use A and C to move', 0, 8, 1)
- oled.text('up and down.', 0, 16, 1)
- oled.text('Press A to continue', 0, 24, 1)
- oled.show()
- wait_for_A()
- oled.fill(0)
- oled.text('Instructions (cont.):', 0, 0, 1)
- oled.text('Press B to select a', 0, 8, 1)
- oled.text('program.', 0, 16, 1)
- oled.text('Press A to continue', 0, 24, 1)
- oled.show()
- wait_for_A()
- oled.fill(0)
- oled.text('Instructions (cont.):', 0, 0, 1)
- oled.text('At anytime you can', 0, 8, 1)
- oled.text('press reset to go...', 0, 16, 1)
- oled.text('Press A to continue', 0, 24, 1)
- oled.show()
- wait_for_A()
- oled.fill(0)
- oled.text('Instructions (cont.):', 0, 0, 1)
- oled.text('... back to the main', 0, 8, 1)
- oled.text('screen.', 0, 16, 1)
- oled.text('Press A to continue', 0, 24, 1)
- oled.show()
- wait_for_A()
- oled.fill(0)
- oled.text('Instructions (cont.):', 0, 0, 1)
- oled.text('The programs will', 0, 8, 1)
- oled.text('have there own...', 0, 16, 1)
- oled.text('Press A to continue', 0, 24, 1)
- oled.show()
- wait_for_A()
- oled.fill(0)
- oled.text('Instructions (cont.):', 0, 0, 1)
- oled.text('... instructions.', 0, 8, 1)
- oled.text('Press A to continue', 0, 16, 1)
- oled.text('to menu', 0, 24, 1)
- oled.show()
- wait_for_A()
- oled.fill(0)
- oled.show()
- class Button(DigitalInOut):
- def __init__(self, name, pin, direction=Direction.INPUT, pull=Pull.UP):
- self.name = name
- super().__init__(pin)
- self.direction = direction
- self.pull = pull
- def wait_for_press(self):
- while self.value:
- pass
- names = ["A", "B", "C"]
- pins = [board.D9, board.D6, board.D5]
- buttons = {name: Button(name, pin) for name, pin in zip(names, pins)}
- def print_page(oled, strings):
- oled.fill(0)
- for i, s in enumerate(strings):
- oled.text(s, 0, i * 8, 1)
- oled.show()
- messages = [
- """
- Adafruit Feather
- Program selector
- Press A to continue
- """,
- """
- Instructions:
- Use A and C to move
- up and down
- Press A to continue
- """,
- """
- Instructions (cont.):
- Press B to select a
- program.
- Press A to continue
- """,
- ...
- ]
- for message in messages:
- print_page(oled, message.splitlines()[1:])
- buttons["A"].wait_for_press()
- oled.fill(0)
- oled.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement