[{"element_type":"user_image","content":"https://cdn-learn.adafruit.com/user_assets/assets/000/000/101/original/post1.jpg?1680982275","metadata":{"caption":""}},{"element_type":"markdown","content":"\u003cp\u003e\u003cem\u003eNeed to turn your Elvis jumpsuit up to 11? Adafruit to the rescue.\u003c/em\u003e\u003c/p\u003e\n\u003cp\u003eIn this quick project, we added 40 programmable lights to an off-the-shelf Elvis costume. NeoPixels and CircuitPython made this easy. Wiring it up took a few hours.\u003c/p\u003e\n\u003ch2\u003eParts used:\u003c/h2\u003e\n\u003cul\u003e\n\u003cli\u003e\u003ca href=\"https://www.adafruit.com/product/3333\"\u003eCircuit Playground Express\u003c/a\u003e\u003c/li\u003e\n\u003cli\u003eTwo packs of \u003ca href=\"https://www.adafruit.com/product/1559\"\u003eFlora RGB Smart NeoPixel v2\u003c/a\u003e\n\u003c/li\u003e\n\u003cli\u003e\u003ca href=\"https://www.adafruit.com/product/3915\"\u003eCircuit Playground Express Enclosure\u003c/a\u003e\u003c/li\u003e\n\u003cli\u003e\u003ca href=\"https://www.adafruit.com/product/727\"\u003e3x AAA battery holder with power switch\u003c/a\u003e\u003c/li\u003e\n\u003cli\u003eWires and solder\u003c/li\u003e\n\u003cli\u003eGlue gun and lots of glue sticks\u003c/li\u003e\n\u003cli\u003eVelcro to attach to costume\u003c/li\u003e\n\u003c/ul\u003e\n\u003ch2\u003eHow'd it go?\u003c/h2\u003e\n\u003cp\u003eSuccess! This was for a gymnastics competition awards banquet in Memphis, and it survived the all-night party.\u003c/p\u003e\n\u003cul\u003e\n\u003cli\u003eThe wiring harness was a little too bulky, that could be thinned out a lot.\u003c/li\u003e\n\u003cli\u003eIt only took a little bashed-together python code to make the whole thing appropriately ridiculous:\u003c/li\u003e\n\u003c/ul\u003e\n","metadata":{"markdown":"_Need to turn your Elvis jumpsuit up to 11? Adafruit to the rescue._\n\nIn this quick project, we added 40 programmable lights to an off-the-shelf Elvis costume. NeoPixels and CircuitPython made this easy. Wiring it up took a few hours.\n\n## Parts used:\n- [Circuit Playground Express](https://www.adafruit.com/product/3333)\n- Two packs of [Flora RGB Smart NeoPixel v2](https://www.adafruit.com/product/1559)\n- [Circuit Playground Express Enclosure](https://www.adafruit.com/product/3915)\n- [3x AAA battery holder with power switch](https://www.adafruit.com/product/727)\n- Wires and solder\n- Glue gun and lots of glue sticks\n- Velcro to attach to costume\n\n## How'd it go?\nSuccess! This was for a gymnastics competition awards banquet in Memphis, and it survived the all-night party.\n- The wiring harness was a little too bulky, that could be thinned out a lot.\n- It only took a little bashed-together python code to make the whole thing appropriately ridiculous:"}},{"element_type":"embed","content":"https://player.vimeo.com/video/815900630?h=a75e1f38d4"},{"element_type":"markdown","content":"\u003ch2\u003eStep 1: Planning\u003c/h2\u003e\n\u003cul\u003e\n\u003cli\u003eBought the Elvis costume cape at a local party shop ($30). It's nice; red underside and printed top.\u003c/li\u003e\n\u003cli\u003eUsed a seamripper to split the layers apart JUST at the neck, allowing access to the inside.\u003c/li\u003e\n\u003cli\u003ePhotographed cape and then added 20 colored dots where lights should go.\u003c/li\u003e\n\u003cli\u003e...then said \"nope\" and added (and ordered) 20 more.\u003c/li\u003e\n\u003c/ul\u003e\n","metadata":{"markdown":"## Step 1: Planning\n- Bought the Elvis costume cape at a local party shop ($30). It's nice; red underside and printed top.\n- Used a seamripper to split the layers apart JUST at the neck, allowing access to the inside.\n- Photographed cape and then added 20 colored dots where lights should go.\n- ...then said \"nope\" and added (and ordered) 20 more."}},{"element_type":"user_image","content":"https://cdn-learn.adafruit.com/user_assets/assets/000/000/102/original/post-cape1.jpg?1680985932","metadata":{"caption":""}},{"element_type":"user_image","content":"https://cdn-learn.adafruit.com/user_assets/assets/000/000/103/original/post-cape2.jpg?1680984090","metadata":{"caption":""}},{"element_type":"markdown","content":"\u003cp\u003eThe wiring plan was 7 separate strands with no more than 7 lights per strand, for two reasons:\u003c/p\u003e\n\u003col\u003e\n\u003cli\u003eWhen something broke loose during the party we'd only lose a few lights.\u003c/li\u003e\n\u003cli\u003eNo thin wire would need to carry power for 40 LEDs\u003c/li\u003e\n\u003c/ol\u003e\n\u003cp\u003eDecided not to use conductive thread, because these chains are a bit long, so resistance might be too high.\u003c/p\u003e\n\u003cp\u003eInstead, I ended up using a mismash of spare wires I happened to have, and it ended up a little too thick.\u003c/p\u003e\n","metadata":{"markdown":"The wiring plan was 7 separate strands with no more than 7 lights per strand, for two reasons:\n1. When something broke loose during the party we'd only lose a few lights.\n2. No thin wire would need to carry power for 40 LEDs\n\nDecided not to use conductive thread, because these chains are a bit long, so resistance might be too high.\n\nInstead, I ended up using a mismash of spare wires I happened to have, and it ended up a little too thick."}},{"element_type":"user_image","content":"https://cdn-learn.adafruit.com/user_assets/assets/000/000/104/original/post-cape3.jpg?1680984104","metadata":{"caption":""}},{"element_type":"markdown","content":"\u003ch2\u003eStep 2: Place the lights and wire it up!\u003c/h2\u003e\n\u003cp\u003eThis took a very long time, and I made just a couple of wiring errors but caught those early.\u003c/p\u003e\n\u003cul\u003e\n\u003cli\u003eTape the lights in place on the outside of the cape\u003c/li\u003e\n\u003cli\u003ePoke holes (seamripper again) to get the wires through\u003c/li\u003e\n\u003cli\u003eThread wires from one light to the next, soldering each one in to keep it secure\u003c/li\u003e\n\u003cli\u003eAfter everything's in place and tested, GOOP IT ALL UP with the glue gun, wires and eveything (glue sticks aren't conductive)\u003c/li\u003e\n\u003c/ul\u003e\n","metadata":{"markdown":"## Step 2: Place the lights and wire it up!\nThis took a very long time, and I made just a couple of wiring errors but caught those early.\n- Tape the lights in place on the outside of the cape\n- Poke holes (seamripper again) to get the wires through\n- Thread wires from one light to the next, soldering each one in to keep it secure\n- After everything's in place and tested, GOOP IT ALL UP with the glue gun, wires and eveything (glue sticks aren't conductive)\n\n"}},{"element_type":"user_image","content":"https://cdn-learn.adafruit.com/user_assets/assets/000/000/105/original/post-wires1.jpg?1680985883","metadata":{"caption":""}},{"element_type":"user_image","content":"https://cdn-learn.adafruit.com/user_assets/assets/000/000/106/original/post-wires2.jpg?1680985903","metadata":{"caption":""}},{"element_type":"markdown","content":"\u003cul\u003e\n\u003cli\u003eOnce in a while, connect the wires to CircuitPlayground and run some test code (see full code below)\u003c/li\u003e\n\u003c/ul\u003e\n","metadata":{"markdown":"- Once in a while, connect the wires to CircuitPlayground and run some test code (see full code below)"}},{"element_type":"embed","content":"https://vimeo.com/815900555"},{"element_type":"user_image","content":"https://cdn-learn.adafruit.com/user_assets/assets/000/000/107/original/post-wires3b.jpg?1680986389","metadata":{"caption":""}},{"element_type":"markdown","content":"\u003cp\u003eEverything's working, but it's past midnight and the wiring is a mess! \u0026lt;--- \u003ccode class=\"inline\"\u003eKitty agrees\u003c/code\u003e ^..^\u003c/p\u003e\n\n\u003ch2\u003eStep 3: Finish wiring and write some code\u003c/h2\u003e\n\n\u003cp\u003eLuckily I'd spent more than $30 so the nice folks at Adafruit threw in a solder-style breadboard, perfect for de-horrifying my wires a bit.\u003c/p\u003e\n","metadata":{"markdown":"Everything's working, but it's past midnight and the wiring is a mess! \u0026lt;--- `Kitty agrees` \\^..^\n\n## Step 3: Finish wiring and write some code\nLuckily I'd spent more than $30 so the nice folks at Adafruit threw in a solder-style breadboard, perfect for de-horrifying my wires a bit.\n"}},{"element_type":"user_image","content":"https://cdn-learn.adafruit.com/user_assets/assets/000/000/108/original/post-wires4.jpg?1680986965","metadata":{"caption":""}},{"element_type":"embed","content":"https://player.vimeo.com/video/815914318?h=af4aaeddb2"},{"element_type":"code","content":"#######################################################\n# SparkleCape prototype by EJ March 2023\n#  for Adafruit Circuit Playground Express\n#  Connections:\n#  A1 -\u003e \"red\" light strand in wiring diagram\n#  A2 -\u003e \"yellow\" light strand in wiring diagram\n#  A3 -\u003e \"blue\" light strand in wiring diagram\n#  A4 -\u003e \"green\" light strand in wiring diagram\n#\n#  Warning: This code was written quickly by a monkey, and was not well tested.\n#           It should only be used to look ridiculous while dancing or receiving awards.\n\nimport board\nimport time\nimport digitalio\nimport neopixel\nimport random\n\nprint('Howdy') # Just so I know when Mu connected\n\n# This is the main class; it checks for button presses and updates the lights\nclass SparkleCape():\n    def __init__(self):\n        self.cpg_pixels = neopixel.NeoPixel(board.NEOPIXEL, 10, brightness=0.2, auto_write=False)\n        self.cape_pixels_r = neopixel.NeoPixel(board.A1, 10, brightness=0.5, auto_write=False)\n        self.cape_pixels_y = neopixel.NeoPixel(board.A2, 10, brightness=0.5, auto_write=False)\n        self.cape_pixels_b = neopixel.NeoPixel(board.A3, 10, brightness=0.5, auto_write=False)\n        self.cape_pixels_e = neopixel.NeoPixel(board.A4, 10, brightness=0.5, auto_write=False)\n\n        self.cape_chains = [self.cape_pixels_r, self.cape_pixels_y, self.cape_pixels_b, self.cape_pixels_e]\n        self.num_links = 7\n        self.cape_sparks = [[255]*self.num_links]*len(self.cape_chains)\n        self.base_color = [[255, 0, 0], [255, 255, 0], [0, 0, 255], [0, 255, 0]]\n        self.spark = 255\n        self.current_spark = 0\n        self.spark_drain = 50\n\n        self.sparkle_mode = 0\n        self.num_sparkle_modes = 5\n        self.pressed_last_time = False\n        self.brightness = 255\n        self.buttons = ButtonsModule()\n        self.rainbow_phase = 1\n        self.brite = 0.0\n        self.current_rb = (0,0,0)\n\n\n    # This gets called pretty often to change the light colors\n    def periodic_update(self):\n        # press buttons to change sparkle mode\n        pressed = (self.buttons.left() or self.buttons.right())\n        if pressed and not self.pressed_last_time:\n            self.sparkle_mode = (self.sparkle_mode + 1) % self.num_sparkle_modes\n        self.pressed_last_time = pressed\n\n        # eye and tail lights\n        self.cape_chains[3][0] = (0, 0, self.brightness)\n        self.cape_chains[3][1] = (self.brightness, 0, 0)\n\n\n        # Original white-sparks (this one's my favorite)\n        if self.sparkle_mode == 0:\n            # drift to base color\n            for ci in range(3):\n                for ch in range(self.num_links):\n                    self.cape_chains[ci][ch] = ((self.cape_chains[ci][ch][0]) \u003e\u003e 1,\n                                                (self.cape_chains[ci][ch][1]) \u003e\u003e 1,\n                                                (self.cape_chains[ci][ch][2]) \u003e\u003e 1)\n            # bright sparkles\n            num_new_sparks = 3\n            for i in range(num_new_sparks):\n                r = random.randint(0, 65535)\n                ci = r % 3\n                ch = (r \u003e\u003e 8) % self.num_links\n                self.cape_chains[ci][ch] = (255, 255, 255)\n\n\n        # Rainbow cycle is pretty cool\n        elif self.sparkle_mode in (1, 2):\n            num_colors = 50\n            if self.sparkle_mode == 2:\n                num_colors = 20\n            current_color = self.rainbow_phase\n            self.rainbow_phase += 1\n            self.rainbow_phase %= num_colors\n            self.cape_chains[3][0] = (0, 0, 0)\n            self.cape_chains[3][1] = (0, 0, 0)\n\n            for ch in range(self.num_links):\n                t = int(current_color + 1 * ch) % num_colors\n                rainbow_color = rainbow(t, num_colors)\n                rainbow_color = (rainbow_color[0] \u003e\u003e 1, rainbow_color[1] \u003e\u003e 1, rainbow_color[2] \u003e\u003e 1)\n                for ci in range(3):\n                    self.cape_chains[ci][ch] = rainbow_color\n\n\n        # Rainbow flash (good for dance floor)\n        elif self.sparkle_mode == 3:\n            num_colors = 50\n            self.brite += 0.05\n            if self.brite \u003e 1.0:\n                self.brite = 0.0\n                t = random.randint(0, num_colors - 1)\n                self.current_rb = rainbow(t, num_colors)\n            self.cape_chains[3][0] = (0, 0, 0)\n            self.cape_chains[3][1] = (0, 0, 0)\n            rainbow_color = self.current_rb\n            rainbow_color = (int(rainbow_color[0] * self.brite), int(rainbow_color[1] * self.brite), int(rainbow_color[2] * self.brite))\n\n            for ch in range(self.num_links):\n                for ci in range(3):\n                    self.cape_chains[ci][ch] = rainbow_color\n\n\n        # Original runway test pattern (I used this to verify my wiring was correct)\n        elif self.sparkle_mode == 4:\n            self.spark -= self.spark_drain\n            if self.spark \u003c 0:\n                self.current_spark = (self.current_spark + 1) % self.num_links\n                self.spark = 255\n            for ci in range(3):\n                self.cape_chains[ci][self.current_spark] = (max(self.base_color[ci][0], self.spark),\n                                                  max(self.base_color[ci][1], self.spark),\n                                                  max(self.base_color[ci][2], self.spark))\n\n\n\nclass ButtonsModule:\n    def __init__(self):\n        self.left_button = digitalio.DigitalInOut(board.D4)\n        self.right_button = digitalio.DigitalInOut(board.D5)\n        self.slide_switch = digitalio.DigitalInOut(board.D7)\n        self.left_button.switch_to_input(pull=digitalio.Pull.DOWN)\n        self.right_button.switch_to_input(pull=digitalio.Pull.DOWN)\n        self.slide_switch.switch_to_input(pull=digitalio.Pull.UP)\n    def left(self):\n        if self.left_button is None:\n            return False\n        return self.left_button.value\n    def right(self):\n        if self.right_button is None:\n            return False\n        return self.right_button.value\n    def switch(self):\n        if self.slide_switch is None:\n            return False\n        return self.slide_switch.value\n\n\n# Thanks to https://www.arnevogel.com/rgb-rainbow/\n# Given a complete rainbow of n colors, this returns the ith color\ndef rainbow(i,n):\n    r = 0\n    g = 0\n    b = 0\n    stepsize = int((255*6)/n)\n    progress = i*stepsize\n    sw = int(progress/255)\n    if sw == 0:\n        b = 255\n        r = progress%255\n    elif sw ==1:\n        r = 255\n        b = progress%255\n    elif sw ==2:\n        r = 255\n        g = progress%255\n    elif sw ==3:\n        g = 255\n        r = progress%255\n    elif sw ==4:\n        g = 255\n        b = progress%255\n    elif sw ==5:\n        b = 255\n        g = progress%255\n    return r, g, b\n\n\ndef run_all():\n    cape = SparkleCape()\n\n    while True:\n        cape.periodic_update()\n        time.sleep(0.05)\n\n\nrun_all()","metadata":{"language":"python","linenums":false}}]