Magical 8 Egg

by phowa5 in Circuits > Arduino

16 Views, 0 Favorites, 0 Comments

Magical 8 Egg

IMG_2435.JPG
IMG_2434.JPG
IMG_2436.JPG

I created the Magical 8 Egg as a playful twist on the classic Magic 8 Ball... something familiar but unexpected. I wanted to take the fun of seeking silly fortunes and package it in a new, lighthearted form that feels even more personal and surprising. It’s a reminder not to take life too seriously! Sometimes you just have to shake things up and see what cracks open :)

It took quite a while to get everything right and almost perfect, but in the end it turned out very nice!

Supplies

Wiring the Speaker to the Adafruit Circut

istockphoto-612248188-612x612.jpg
IMG_2430.JPG
IMG_2429.JPG
  1. Take three wires and cut them down to a reasonable length (not too long and not too short)
  2. Strip the ends of each wire
  3. Sauter/Hot glue one end of the wire to the GND hole on the Circuit, and the other end of the wire to the GND hole on the speaker
  4. Sauter/ Hot glue one end of the wire to the 3.3V hole on the Circuit to the POWER hole on the speaker
  5. Sauter/ hot glue one end of the wire to the A0 hole on the Circuit to the SIGNAL hole on the speaker
  6. Turn on the Battery pack and play a tune on your Circuit to make sure the sound comes out from the speaker and not the Adafruit Circuit speakers
  7. Here is a simple Tune to play if you are struggling!

Setting Up the Inside

IMG_2342.JPG
IMG_2345.JPG
IMG_2428.JPG
IMG_2431.JPG
IMG_2432.JPG
  1. Take the Battery pack and tape it to the bottom of the egg (make sure there are batteries in the pack first!)
  2. Attach the Adafruit Circuit to the battery pack
  3. Hot glue the circuit to the battery pack right on top
  4. Take the wires and fold them so they are more contained, and tape them together
  5. tape the grouped wires to the wall of the egg

~ (After you decorate the egg) ~

  1. Melt holes with the hot glue gun at the bottom of the egg lid
  2. Attach the speaker to where you just melted holes with tape
  3. Close the lid


Decorating the Egg

IMG_2343.JPG
IMG_2433.JPG
IMG_2436.JPG
  1. Take the pearls and hot glue them to the lid of the egg to form an "8" or decorate however you like
  2. Use the white paint and paint the inside of the lid so the wires can't be seen

(Go back to step 2)


The Code (Python)

import time

import random

import math

from adafruit_circuitplayground import cp


SHAKE_ACCEL_THRESHOLD = 15 # Tune this if needed


print("Magic 8-Ball is ready. Shake to get an answer!")


def is_shaken():

x, y, z = cp.acceleration

magnitude = (x**2 + y**2 + z**2) ** 0.5

print(f"Accel magnitude: {magnitude:.2f}")

return magnitude > SHAKE_ACCEL_THRESHOLD


def play_sound(filename):

print(f"Playing sound: {filename}")

cp.play_file(filename)

print("Sound finished.")


# Pulses a color with each answer

def pulse_color(color, duration=3): # 3 seconds

print(f"Pulsing color: {color} for {duration} seconds")

start = time.monotonic()

while time.monotonic() - start < duration:

level = (math.sin(time.monotonic() * 2 * math.pi / 2) + 1) / 2

brightness = int(level * 50)

scaled_color = tuple(int(c * brightness / 255) for c in color)

cp.pixels.fill(scaled_color)

time.sleep(0.05)

cp.pixels.fill((0, 0, 0))

print("Color done.")


while True:

if is_shaken():

print("Shake detected!")

choice = random.choice(["yolk yes", "shell no", "scrambled", "fortune"])

print(f"Random choice: {choice}")


if choice == "yolk yes":

play_sound("yolk yes.wav")

pulse_color((0, 255, 0), duration=5) # Green


elif choice == "shell no":

play_sound("shell no.wav")

pulse_color((255, 0, 0), duration=5) # Red


elif choice == "scrambled":

play_sound("scrambled.wav")

pulse_color((255, 150, 0), duration=5) # Yellow


elif choice == "fortune":

play_sound("fortune.wav")

pulse_color((0, 0, 255), duration=5) # Blue


print("Waiting for next shake...\n")

time.sleep(2) # Prevent immediate retrigger


time.sleep(0.1)