raspberry pi zero based drum machine
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

display_test.py 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
  2. # SPDX-License-Identifier: MIT
  3. import digitalio
  4. import board
  5. from adafruit_rgb_display.rgb import color565
  6. import adafruit_rgb_display.st7789 as st7789
  7. # Configuration for CS and DC pins for Raspberry Pi
  8. cs_pin = digitalio.DigitalInOut(board.CE0)
  9. dc_pin = digitalio.DigitalInOut(board.D25)
  10. reset_pin = None
  11. BAUDRATE = 64000000 # The pi can be very fast!
  12. # Create the ST7789 display:
  13. display = st7789.ST7789(
  14. board.SPI(),
  15. cs=cs_pin,
  16. dc=dc_pin,
  17. rst=reset_pin,
  18. baudrate=BAUDRATE,
  19. width=135,
  20. height=240,
  21. x_offset=53,
  22. y_offset=40,
  23. )
  24. backlight = digitalio.DigitalInOut(board.D22)
  25. backlight.switch_to_output()
  26. backlight.value = True
  27. buttonA = digitalio.DigitalInOut(board.D23)
  28. buttonB = digitalio.DigitalInOut(board.D24)
  29. buttonA.switch_to_input()
  30. buttonB.switch_to_input()
  31. # Main loop:
  32. while True:
  33. if buttonA.value and buttonB.value:
  34. backlight.value = False # turn off backlight
  35. else:
  36. backlight.value = True # turn on backlight
  37. if buttonB.value and not buttonA.value: # just button A pressed
  38. display.fill(color565(255, 0, 0)) # red
  39. if buttonA.value and not buttonB.value: # just button B pressed
  40. display.fill(color565(0, 0, 255)) # blue
  41. if not buttonA.value and not buttonB.value: # none pressed
  42. display.fill(color565(0, 255, 0)) # green