|
| 1 | +# SPDX-FileCopyrightText: 2017 John Edgar Park for Adafruit Industries |
| 2 | +# |
| 3 | +# SPDX-License-Identifier: MIT |
| 4 | + |
| 5 | +# CircuitPython Gemma Gear goggles |
| 6 | +# uses two 16 NeoPixel rings (RGBW) |
| 7 | +# connected to Gemma M0 powered by LiPo battery |
| 8 | + |
| 9 | +import time |
| 10 | + |
| 11 | +import board |
| 12 | +import neopixel |
| 13 | + |
| 14 | +pixpinLeft = board.D1 # Data In attached to Gemma pin D1 |
| 15 | +pixpinRight = board.D0 # Data In attached to Gemma pin D0 |
| 16 | +numpix = 16 |
| 17 | + |
| 18 | +# uncomment the lines below for RGB NeoPixels |
| 19 | +stripLeft = neopixel.NeoPixel(pixpinLeft, numpix, bpp=3, brightness=.18, |
| 20 | + auto_write=False) |
| 21 | +stripRight = neopixel.NeoPixel(pixpinRight, numpix, bpp=3, brightness=.18, |
| 22 | + auto_write=False) |
| 23 | + |
| 24 | + |
| 25 | +# Use these lines for RGBW NeoPixels |
| 26 | +# stripLeft = neopixel.NeoPixel(pixpinLeft, numpix, bpp=4, brightness=.18, |
| 27 | +# auto_write=False) |
| 28 | +# stripRight = neopixel.NeoPixel(pixpinRight, numpix, bpp=4, brightness=.18, |
| 29 | +# auto_write=False) |
| 30 | + |
| 31 | + |
| 32 | +def cog(pos): |
| 33 | + # Input a value 0 to 255 to get a color value. |
| 34 | + # Note: switch the commented lines below if using RGB vs. RGBW NeoPixles |
| 35 | + if (pos < 8) or (pos > 250): |
| 36 | + # return (120, 0, 0, 0) #first color, red: for RGBW NeoPixels |
| 37 | + return (120, 0, 0) # first color, red: for RGB NeoPixels |
| 38 | + if pos < 85: |
| 39 | + return (int(pos * 3), int(255 - (pos * 3)), 0) |
| 40 | + # return (125, 35, 0, 0) #second color, brass: for RGBW NeoPixels |
| 41 | + # return (125, 35, 0) # second color, brass: for RGB NeoPixels |
| 42 | + elif pos < 170: |
| 43 | + pos -= 85 |
| 44 | + # return (int(255 - pos*3), 0, int(pos*3), 0)#: for RGBW NeoPixels |
| 45 | + return (int(255 - pos * 3), 0, int(pos * 3)) # : for RGB NeoPixels |
| 46 | + else: |
| 47 | + pos -= 170 |
| 48 | + # return (0, int(pos*3), int(255 - pos*3), 0)#: for RGBW NeoPixels |
| 49 | + return (0, int(pos * 3), int(255 - pos * 3)) # : for RGB NeoPixels |
| 50 | + |
| 51 | + |
| 52 | +def brass_cycle(wait, patternL, patternR): |
| 53 | + # patterns do different things, try: |
| 54 | + # 1 blink |
| 55 | + # 24 chase w pause |
| 56 | + # 64 chase |
| 57 | + # 96 parial chase |
| 58 | + # 128 half turn |
| 59 | + # 230 quarter turn w blink |
| 60 | + # 256 quarter turn |
| 61 | + for j in range(255): |
| 62 | + for i in range(len(stripLeft)): |
| 63 | + idxL = int((i * patternL / len(stripLeft)) + j) |
| 64 | + stripLeft[i] = cog(idxL & 64) # sets the second (brass) color |
| 65 | + idxR = int((i * patternR / len(stripRight)) + j) |
| 66 | + stripRight[i] = cog(idxR & 64) # sets the second (brass) color |
| 67 | + stripLeft.show() |
| 68 | + stripRight.show() |
| 69 | + time.sleep(wait) |
| 70 | + |
| 71 | + |
| 72 | +while True: |
| 73 | + brass_cycle(0.01, 256, 24) # brass color cycle with 1ms delay per step |
| 74 | + # patternL, patternR |
0 commit comments