CircuitPython Setup

To get started, you'll want to set up your HalloWing by following this guide. When you're ready, and can upload code to the board return here.

Adafruit really likes using the Mu editor to edit the CircuitPython code. See this guide on loading and using Mu.

Libraries

You'll also need to add a code library for this project. Follow this guide on adding libraries. The only one you'll need is the neopixl.mpy file from the Circuit Python bundle in the 'lib' folder, so just drag it from your downloaded, unziped 'lib' folder onto the HalloWing.

Sound Files

The code was designed to call on seven different sound effects. These growls and screams come to us courtesy of the Creative Commons 3.0 licensed sound pack by Freesound.org user enochrooted.

Download this zip file and uncompress it to get the sounds. Drag the .wav files onto your HalloWing (it will show up as the USB drive CIRCUITPY).

Code

Here is the code we'll use. Copy it and then paste in Mu. Save it to your HalloWing as code.py

# SPDX-FileCopyrightText: 2018 John Edgar Park for Adafruit Industries
#
# SPDX-License-Identifier: MIT

import time
import board
import digitalio
import audioio
import audiocore
import neopixel

# user variables
pix_rate = 0.03  # Increase the number to slow down the color chase
blink_times = 2  # number of times the eyes blink between color chases
blink_speed = 0.1  # speed of the blinks, lower numbers are faster
rest_time = 3  # time between color changes e.g. '3' = 3 sec, '300'= 5 mins.

#  setup
NEOPIXEL_PIN = board.EXTERNAL_NEOPIXEL
NUM_PIXELS = 30
pixels = neopixel.NeoPixel(NEOPIXEL_PIN, NUM_PIXELS)


led = digitalio.DigitalInOut(board.D13)
led.direction = digitalio.Direction.OUTPUT
led.value = True
time.sleep(0.5)

ORANGE = (255, 30, 0)
PURPLE = (200, 0, 255)
RED = (255, 0, 0)
GREEN = (0, 255, 0)
BLACK = (0, 0, 0)

COLORS = [ORANGE, PURPLE, RED, GREEN, ORANGE, PURPLE, RED]

pixels.fill(ORANGE)
pixels.show()

def color_chase(color, wait):
    for i in range(NUM_PIXELS):
        pixels[i] = color
        time.sleep(wait)
        pixels.show()


def blink(times, speed):
    for _ in range(times):
        led.value = False
        time.sleep(speed)
        led.value = True
        time.sleep(speed)

def play_waves(file_num):
    wave_file = open(wave_files[file_num], "rb")  # open a wav file
    wave = audiocore.WaveFile(wave_file)
    audio.play(wave)  # play the wave file
    while audio.playing:  # allow the wav to finish playing
        pass
    wave_file.close()  # close the wav file

wave_files = ["alex_deepgrowl1.wav", "alex-highgrowl1.wav", "alex-squeal1.wav",
              "toni-deepgrowl.wav", "toni-highgrowl2.wav","toni-pigsqueal.wav",
              "toni-pitchedscream2.wav"]
audio = audioio.AudioOut(board.A0)

while True:
    for k in range(len(wave_files)):
        blink(blink_times, blink_speed)
        color_chase(COLORS[k], pix_rate)
        play_waves(k)
        time.sleep(rest_time)

With the code uploaded to your HalloWing you can now turn down the lights and get ready for the wonderful creepiness of your Milk Jug Glow Skull! Perfect for decorating for Halloween, or even year-round!

This guide was first published on Sep 14, 2018. It was last updated on Mar 27, 2024.

This page (Code with CircuitPython) was last updated on Mar 27, 2024.

Text editor powered by tinymce.