Christmas House

This Christmas display is powered by a CPX/Crickit and programed with CircuitPython. The Christmas trees and house are made of thin wood cut on a CO2 laser cutter. The ballerina spins when the magnetic door sensor is opened. The cuckoo like bird and soldiers are activated by capacitative touch.

Here is the Code:
CHRISTMAS HOUSE with CPX/Crickit
import time
import board
from adafruit_crickit import crickit
# from adafruit_circuitplayground import cp
import audioio
import audiocore
# import motor

ss = crickit.seesaw

wavfile = "nc4.wav"
f = open(wavfile, "rb")
wav = audiocore.WaveFile(f)

wavfile2 = "cc.wav"
f2 = open(wavfile2, "rb")
wav2 = audiocore.WaveFile(f2)

wavfile3 = "soilders1.wav"
f3 = open(wavfile3, "rb")
wav3 = audiocore.WaveFile(f3)

a = audioio.AudioOut(board.A0)

DOOR_1 = crickit.SIGNAL1   
ss.pin_mode(DOOR_1, ss.INPUT_PULLUP)

while True:
    if not ss.digital_read(DOOR_1):
        print("Door is closed")
        time.sleep(.1)
    else:
        print("Door is open")
        time.sleep(.1)
        a.play(wav)
        print("playing")
        for i in range(0, 2, 1):
            crickit.dc_motor_1.throttle = 0.3
            time.sleep(.5)
            crickit.dc_motor_1.throttle = -0.3
            time.sleep(.5)
        for i in range(0, 6, 1):
            crickit.dc_motor_1.throttle = 0.3
            time.sleep(.2)
            crickit.dc_motor_1.throttle = -0.3
            time.sleep(.2)
            crickit.dc_motor_1.throttle = 0
            time.sleep(.1)
        crickit.dc_motor_1.throttle = .3
        time.sleep(2.3)
        crickit.dc_motor_1.throttle = 0
        # f.close()
        time.sleep(2)
        crickit.dc_motor_1.throttle = 0
    if crickit.touch_1.value:
        print("touched pad 1")
        a.play(wav2)
        servo_1 = crickit.servo_1
        servo_1.angle = 140
        time.sleep(.3)
        for i in range(1, 3, 1):
            servo_1.angle = 50
            time.sleep(.2)
            servo_1.angle = 100
            time.sleep(.2)
        servo_1.angle = 20
        time.sleep(1)
    if crickit.touch_4.value:
        print("touched pad 4")
        a.play(wav3)
        servo_4 = crickit.servo_4
        servo_3 = crickit.servo_3
        servo_4.angle = 150
        servo_3.angle = 150
        time.sleep(.5)
        for i in range(1, 2, 1):
            servo_4.angle = 100
            servo_3.angle = 100
            time.sleep(.2)
            servo_4.angle = 130
            servo_3.angle = 130
            time.sleep(.2)
        for i in range(0, 5, 1):
            servo_4.angle = 20
            servo_3.angle = 20
            time.sleep(.4)
            servo_4.angle = 70
            servo_3.angle = 70
            time.sleep(.4)
        servo_4.angle = 170
        servo_3.angle = 170
        time.sleep(.4)
        servo_4.angle = 0
        servo_3.angle = 0
        time.sleep(1)
        time.sleep(1)
        

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s