|
| 1 | +import time |
| 2 | +import board |
| 3 | +import neopixel |
| 4 | + |
| 5 | +pixel_count = 6 # Number of NeoPixels |
| 6 | +pixel_pin = board.D1 # Pin where NeoPixels are connected |
| 7 | + |
| 8 | +speed = .1 # Animation speed (in seconds). |
| 9 | + # This is how long to spend in a single animation frame. |
| 10 | + # Higher values are slower. |
| 11 | + # Good values to try are 400, 200, 100, 50, 25, etc. |
| 12 | + |
| 13 | +animation = 0 # Type of animation, can be one of these values: |
| 14 | + # 0 - Solid color pulse |
| 15 | + # 1 - Moving color pulse |
| 16 | + |
| 17 | +color_steps = 8 # Number of steps in the animation. |
| 18 | + |
| 19 | +brightness = 1.0 # 0-1, higher number is brighter |
| 20 | + |
| 21 | + |
| 22 | +# Adjacent colors (on color wheel). |
| 23 | +# red yellow |
| 24 | +color_animation = ([255, 0, 0], [255, 36, 0], [255, 72, 0], [255, 109, 0], |
| 25 | + [255, 145, 0], [255, 182, 0], [255, 218, 0], [255, 255, 0]) |
| 26 | + |
| 27 | +# Adjacent colors |
| 28 | +#([255, 0, 0], [255, 36, 0], [255, 72, 0], [255, 109, 0], |
| 29 | +# [255, 145, 0], [255, 182, 0], [255, 218, 0], [255, 255, 0]) # red yellow |
| 30 | +#([255, 255, 0], [218, 255, 0], [182, 255, 0], [145, 255, 0], |
| 31 | +# [109, 255, 0], [72, 255, 0], [36, 255, 0], [0, 255, 0]) # yello green |
| 32 | +#([0, 255, 0], [0, 255, 36], [0, 255, 72], [0, 255, 109], |
| 33 | +# [0, 255, 145], [0, 255, 182], [0, 255, 218], [0, 255, 255]) # green cyan |
| 34 | +#([0, 255, 255], [0, 218, 255], [0, 182, 255], [0, 145, 255], |
| 35 | +# [0, 109, 255], [0, 72, 255], [0, 36, 255], [0, 0, 255]) # cyan blue |
| 36 | +#([0, 0, 255], [36, 0, 255], [72, 0, 255], [109, 0, 255], |
| 37 | +# [145, 0, 255], [182, 0, 255], [218, 0, 255], [255, 0, 255]) # blue magenta |
| 38 | +#([255, 0, 255], [255, 0, 218], [255, 0, 182], [255, 0, 145], |
| 39 | +# [255, 0, 109], [255, 0, 72], [255, 0, 36], [255, 0, 0]) # magenta red |
| 40 | + |
| 41 | +# Complimentary colors |
| 42 | +#([255, 0, 0], [218, 36, 36], [182, 72, 72], [145, 109, 109], |
| 43 | +# [109, 145, 145], [72, 182, 182], [36, 218, 218], [0, 255, 255]) # red cyan |
| 44 | +#([255, 255, 0], [218, 218, 36], [182, 182, 72], [145, 145, 109], |
| 45 | +# [109, 109, 145], [72, 72, 182], [36, 36, 218], [0, 0, 255]) # yellow blue |
| 46 | +#([0, 255, 0], [36, 218, 36], [72, 182, 72], [109, 145, 109], |
| 47 | +# [145, 109, 145], [182, 72, 182], [218, 36, 218], [255, 0, 255]) # green magenta |
| 48 | + |
| 49 | +# Other combos |
| 50 | +#([255, 0, 0], [218, 36, 0], [182, 72, 0], [145, 109, 0], |
| 51 | +# [109, 145, 0], [72, 182, 0], [36, 218, 0], [0, 255, 0]) # red green |
| 52 | +#([255, 255, 0], [218, 255, 36], [182, 255, 72], [145, 255, 109], |
| 53 | +# [109, 255, 145], [72, 255, 182], [36, 255, 218], [0, 255, 255]) # yellow cyan |
| 54 | +#([0, 255, 0], [0, 218, 36], [0, 182, 72], [0, 145, 109], |
| 55 | +# [0, 109, 145], [0, 72, 182], [0, 36, 218], [0, 0, 255]) # green blue |
| 56 | +#([0, 255, 255], [36, 218, 255], [72, 182, 255], [109, 145, 255], |
| 57 | +# [145, 109, 255], [182, 72, 255], [218, 36, 255], [255, 0, 255]) # cyan magenta |
| 58 | +#([0, 0, 255], [36, 0, 218], [72, 0, 182], [109, 0, 145], |
| 59 | +# [145, 0, 109], [182, 0, 72], [218, 0, 36], [255, 0, 0]) # blue red |
| 60 | +#([255, 0, 255], [255, 36, 218], [255, 72, 182], [255, 109, 145], |
| 61 | +# [255, 145, 109], [255, 182, 72], [255, 218, 36], [255, 255, 0]) # magenta yellow |
| 62 | + |
| 63 | +# Solid colors fading to dark |
| 64 | +#([255, 0, 0], [223, 0, 0], [191, 0, 0], [159, 0, 0], |
| 65 | +# [127, 0, 0], [95, 0, 0], [63, 0, 0], [31, 0, 0]) # red |
| 66 | +#([255, 153, 0], [223, 133, 0], [191, 114, 0], [159, 95, 0], |
| 67 | +# [127, 76, 0], [95, 57, 0], [63, 38, 0], [31, 19, 0]) # orange |
| 68 | +#([255, 255, 0], [223, 223, 0], [191, 191, 0], [159, 159, 0], |
| 69 | +# [127, 127, 0], [95, 95, 0], [63, 63, 0], [31, 31, 0]) # yellow |
| 70 | +#([0, 255, 0], [0, 223, 0], [0, 191, 0], [0, 159, 0], |
| 71 | +# [0, 127, 0], [0, 95, 0], [0, 63, 0], [0, 31, 0]) # green |
| 72 | +#([0, 0, 255], [0, 0, 223], [0, 0, 191], [0, 0, 159], |
| 73 | +# [0, 0, 127], [0, 0, 95], [0, 0, 63], [0, 0, 31]) # blue |
| 74 | +#([75, 0, 130], [65, 0, 113], [56, 0, 97], [46, 0, 81], |
| 75 | +# [37, 0, 65], [28, 0, 48], [18, 0, 32], [9, 0, 16]) # indigo |
| 76 | +#([139, 0, 255], [121, 0, 223], [104, 0, 191], [86, 0, 159], |
| 77 | +# [69, 0, 127], [52, 0, 95], [34, 0, 63], [17, 0, 31]) # violet |
| 78 | +#([255, 255, 255], [223, 223, 223], [191, 191, 191], [159, 159, 159], |
| 79 | +# [127, 127, 127], [95, 95, 95], [63, 63, 63], [31, 31, 31]) # white |
| 80 | +#([255, 0, 0], [255, 153, 0], [255, 255, 0], [0, 255, 0], |
| 81 | +# [0, 0, 255], [75, 0, 130], [139, 0, 255], [255, 255, 255]) # rainbow colors |
| 82 | + |
| 83 | +# Global state used by the sketch |
| 84 | +strip = neopixel.NeoPixel(pixel_pin, pixel_count, brightness=1, auto_write=False) |
| 85 | + |
| 86 | +while True: # Loop forever... |
| 87 | + |
| 88 | + # Main loop will update all the pixels based on the animation. |
| 89 | + for i in range(pixel_count): |
| 90 | + |
| 91 | + # Animation 0, solid color pulse of all pixels. |
| 92 | + if animation == 0: |
| 93 | + current_step = (time.monotonic() / speed) % (color_steps * 2 - 2) |
| 94 | + if current_step >= color_steps: |
| 95 | + current_step = color_steps - (current_step - (color_steps - 2)) |
| 96 | + |
| 97 | + # Animation 1, moving color pulse. Use position to change brightness. |
| 98 | + elif animation == 1: |
| 99 | + current_step = (time.monotonic() / speed + i) % (color_steps * 2 - 2) |
| 100 | + if current_step >= color_steps: |
| 101 | + current_step = color_steps - (current_step - (color_steps - 2)) |
| 102 | + |
| 103 | + strip[i] = color_animation[int(current_step)] |
| 104 | + |
| 105 | + # Show the updated pixels. |
| 106 | + strip.show() |
0 commit comments