Movalite (אורנוע) is a motion sensitive bling based on an Adafruit Circuit Playground Bluefruit board.
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

code.py 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. """
  2. Movalite by The Dod:
  3. Adafruit CircuitPlayground Bluefruit motion-sensitiuve "bling"
  4. The RGB levels of neopixels around the circuit are affected
  5. by X/Y/Z acceleration
  6. Controls:
  7. slider switch: normal/standby mode
  8. button a: increase brightness
  9. button b: decrease brightness
  10. """
  11. import math
  12. import time
  13. from adafruit_circuitplayground import cp
  14. NUM_PIXELS = 10
  15. # Like a clock, with connectors at 12 (USB) and 6 (power)
  16. LED_ANGLES = [
  17. i*math.pi/6.0
  18. for i in [11, 10, 9, 8, 7, 5, 4, 3, 2, 1]]
  19. minx = miny = minz = -5.0
  20. maxx = maxy = maxz = 5.0
  21. cp.pixels.brightness = 0.1
  22. is_standby = cp.switch
  23. last_click = 0
  24. DEBOUNCE = 0.25
  25. def angles2level(led, val):
  26. led_angle = LED_ANGLES[led]
  27. val_angle = val * 2.0 * math.pi
  28. angle = led_angle - val_angle
  29. while angle > 2 * math.pi:
  30. angle -= 2*math.pi
  31. # the pow() makes sin() values sharper
  32. return int(255*pow(math.sin(angle/2), 4))
  33. while True:
  34. if time.monotonic() > last_click+DEBOUNCE:
  35. if is_standby != cp.switch:
  36. is_standby = cp.switch
  37. last_click = time.monotonic()
  38. if is_standby:
  39. for i in range(NUM_PIXELS):
  40. cp.pixels[i] = (0, 0, 0)
  41. if cp.button_b:
  42. last_click = time.monotonic()
  43. cp.pixels.brightness = max(0.05, cp.pixels.brightness*0.9)
  44. elif cp.button_a:
  45. last_click = time.monotonic()
  46. cp.pixels.brightness = min(0.95, 1.0-(1.0-cp.pixels.brightness)*0.9)
  47. if not is_standby:
  48. x, y, z = cp.acceleration
  49. if x < minx:
  50. minx = x
  51. if y < miny:
  52. miny = y
  53. if z < minz:
  54. minz = z
  55. if x > maxx:
  56. maxx = x
  57. if y > maxy:
  58. maxy = y
  59. if z > maxz:
  60. maxz = z
  61. vals = (
  62. (x-minx)/(maxx-minx),
  63. (y-miny)/(maxy-miny),
  64. (z-minz)/(maxz-minz))
  65. for i in range(NUM_PIXELS):
  66. cp.pixels[i] = (
  67. angles2level(i, vals[0]),
  68. angles2level(i, vals[1]),
  69. angles2level(i, vals[2]))
  70. time.sleep(0.01)