Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
Published © CC BY-NC

Rocket Nightlight

Every well functioning adult needs a nightlight, and we're building one that's touch activated and space themed!

IntermediateFull instructions provided10 hours421
Rocket Nightlight

Things used in this project

Hardware components

Raspberry Pi 4 Model B
Raspberry Pi 4 Model B
×1
Adafruit CAP1188 Capacitive Touch
×1
NeoPixel Ring: WS2812 5050 RGB LED
Adafruit NeoPixel Ring: WS2812 5050 RGB LED
×1
Lamp
×1
Copper Tape
×1
Fluff
×1
Primer
×1
Spray Paint
×1
Sanding Tool
×1
Duct Tape
×1

Hand tools and fabrication machines

3D Printer (optional)

Story

Read more

Code

rocket.py

Python
import time
import board
import busio
from adafruit_cap1188.i2c import CAP1188_I2C
import neopixel

#cap Touch setup
print('Setting up capacitive touch')
i2c = busio.I2C(board.SCL, board.SDA)
cap = CAP1188_I2C(i2c)
cap[1].recalibrate()
time.sleep(1)

# Set up pixels
pixels = neopixel.NeoPixel(board.D18, 30)

# Keep track of state
lastState = False

def checkTouch():

    if cap[1].value:
        print('Touched!')
        return True
    else:
        return False

print('Starting')
while True:

    if checkTouch():

        # set speed of change
        colour = (0,0,255)
        rangeNuber = 110
        steps = 0.01
        sleepTime = 0.01

        # If last state was on, now turn off
        if lastState == True:

            for i in range(1,rangeNuber):

                pixels.brightness = 1 - (i *steps)
                pixels.fill(colour)
                time.sleep(sleepTime)
                pixels.brightness = 0

            lastState = False
            time.sleep(2)

        # If last state was off, now turn on
        elif lastState == False:

            for i in range(1,rangeNuber):
                pixels.brightness = i * steps
                pixels.fill(colour)
                time.sleep(sleepTime)
            
            lastState = True
            time.sleep(2)

    time.sleep(0.5)

Credits

Comments