a circuit playground express wizard staff
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.

54 lines
1.4 KiB

  1. from wzrd_util import *
  2. # Accelerometer stuff not used at the moment:
  3. # import adafruit_lis3dh
  4. # import digitalio
  5. import adafruit_thermistor
  6. import analogio
  7. import blinkenring
  8. import board
  9. import busio
  10. import neopixel
  11. import time
  12. import urandom
  13. # Hardware SPI setup for accelerometer, maybe (does not work):
  14. # spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
  15. # cs = digitalio.DigitalInOut(board.D8) # Set to appropriate CS pin!
  16. # lis3dh = adafruit_lis3dh.LIS3DH_SPI(spi, cs)
  17. # https://github.com/adafruit/Adafruit_CircuitPython_Thermistor
  18. thermistor = adafruit_thermistor.Thermistor(board.TEMPERATURE, 10000, 10000, 25, 3950)
  19. random_pin = analogio.AnalogIn(board.A4)
  20. photocell = analogio.AnalogIn(board.A8)
  21. # Initial setup:
  22. tick_duration = 0.1
  23. last_photocell = photocell_value(photocell)
  24. frame = 0
  25. max_frame = 30
  26. max_bright = 0.35
  27. ext_ring = blinkenring.BlinkenRing(board.A3, 24, 6)
  28. onboard_ring = blinkenring.BlinkenRing(board.NEOPIXEL, 10, 5)
  29. # ext_ring.party_mode = True
  30. # onboard_ring.party_mode = True
  31. while True:
  32. frame += 1
  33. ext_ring.animate()
  34. onboard_ring.animate()
  35. if frame == int(max_frame / 2):
  36. ext_ring.set_color(get_color_for_temp(thermistor.temperature))
  37. # reset frame counter
  38. if frame > max_frame:
  39. urandom.seed(random_pin.value)
  40. onboard_ring.set_color(ext_ring.get_color())
  41. ext_ring.randomize_color()
  42. frame = 0
  43. time.sleep(tick_duration)