Ashok R
Published © CC BY-ND

Animated Lighting CAP with Gesture Control

This CAP is made with programmable LED's and Radar sensor is used to change light modes with gesture.

BeginnerShowcase (no instructions)16 hours353
Animated Lighting CAP with Gesture Control

Things used in this project

Hardware components

Raspberry Pi Pico
Raspberry Pi Pico
×1
NeoPixel Ring: WS2812 5050 RGB LED
Adafruit NeoPixel Ring: WS2812 5050 RGB LED
×1
Flora RGB Neopixel LEDs- Pack of 4
Adafruit Flora RGB Neopixel LEDs- Pack of 4
×2
Infineon BGT60LTR11AIP
×1
Adafruit TPS61023 Mini Boost
×1
Adafruit Noods Flexi LED
×1
nLiten Forward-Emitting 10 LED strip
nLITEn Tech nLiten Forward-Emitting 10 LED strip
×2
nLITEn Power Injector
nLITEn Tech nLITEn Power Injector
×1
Li-ion Battery 3.2V
×1

Hand tools and fabrication machines

Thonny IDE

Story

Read more

Schematics

Schematic

Code

main code

MicroPython
import time
import random
from machine import Pin
from neopixel import Neopixel

blink = 0
mode_sel = 0
led1 = Pin(22, Pin.OUT)
motion = Pin(27, Pin.IN,Pin.PULL_UP)
direction = Pin(26,Pin.IN,Pin.PULL_UP)
numpix = 22
pixels = Neopixel(numpix, 0, 28, "GRBW")
toggle_dir = 0
colori = [(255, 100, 0,0),(255, 50, 0,0),(0, 255, 0,0),(0, 0, 255,0),(255, 0, 0,0), (255, 192, 203,0),(143, 0, 255,0),(0,0,0,255) ]
colori[0] = yellow = (255, 100, 0,0)
colori[1] = orange = (255, 50, 0,0)
colori[2] = green = (0, 255, 0,0)
colori[3] = blue = (0, 0, 255,0)
colori[4] = red = (255, 0, 0,0)
colori[5] = pink = (255, 192, 203,0)
colori[6] = violet = (143, 0, 255,0)
colori[7] = white = (0,0,0,255)
pixels.brightness(25)
#pixels.set_pixel_line(1, 7, red)
#pixels.fill(orange)
#pixels.set_pixel_line_gradient(3, 4, green, blue)
#pixels.set_pixel_line(4, 6, red)
pixels.fill((0, 0, 0))
#pixels.fill(red)
#time.sleep(3)

pixels.show()


def rainbow_move(time_ms):
    for i in range(neopix_size):
        pixel_index = random.randint(0, 22) * 256 // neopix_size
        # random.randint(200, 256) // neopix_size
        neopix[i] = colorwheel((pixel_index) & 255)
        neopix.show()
    time.sleep(time_ms)

def set_mode(mode):
    global blink, colori
    if mode == 0:
        blink = 0
        pixels.fill(green)
    if mode == 1:
        pixels.fill((0,0,0,255))
    if mode == 2:
        rand_i = random.randint(0, 7)
        pixels.fill(colori[rand_i])
    if mode == 3:
        pixels.set_pixel_line(0, 3, blue)
        pixels.set_pixel_line(4, 7, green)
        pixels.set_pixel_line(8, 11, red)
        pixels.set_pixel_line(12, 15, yellow)
        pixels.set_pixel_line(16, 21, orange)
    if mode == 4:
        pixels.set_pixel_line(0, 15, pink)
        pixels.set_pixel_line(16, 21, blue)
    if mode == 5:
        pixels.set_pixel_line(0, 3, orange)
        pixels.set_pixel_line(4, 7, yellow)
        pixels.set_pixel_line(8, 11, violet)
        pixels.set_pixel_line(12, 15, orange)
        pixels.set_pixel_line(16, 21, blue)
    if mode == 6:
        pixels.set_pixel_line(0, 15, white)
        pixels.set_pixel(16, orange)
        pixels.set_pixel(17, green)
        pixels.set_pixel(18, red)
        pixels.set_pixel(19, yellow)
        pixels.set_pixel(20, pink)
        pixels.set_pixel(21, blue)
    if mode == 7:
        pixels.set_pixel(0, pink)
        pixels.set_pixel(1, blue)
        pixels.set_pixel(2, yellow)
        pixels.set_pixel(3, orange)
        pixels.set_pixel(4, green)
        pixels.set_pixel(5, blue)
        pixels.set_pixel(6, violet)
        pixels.set_pixel(7, yellow)
        pixels.set_pixel(8, green)
        pixels.set_pixel(9, blue)
        pixels.set_pixel(10, green)
        pixels.set_pixel(11, orange)
        pixels.set_pixel(12, violet)
        pixels.set_pixel(13, red)
        pixels.set_pixel(14, orange)
        pixels.set_pixel(15, yellow)
        pixels.set_pixel(16, orange)
        pixels.set_pixel(17, red)
        pixels.set_pixel(18, green)
        pixels.set_pixel(19, yellow)
        pixels.set_pixel(20, pink)
        pixels.set_pixel(21, blue)
    if mode == 8:
        pixels.rotate_left(1)
    if mode == 9:
        pixels.rotate_right(2)
    if mode == 10:
        blink = 1
        pixels.set_pixel(0, pink)
        pixels.set_pixel(1, blue)
        pixels.set_pixel(2, yellow)
        pixels.set_pixel(3, orange)
        pixels.set_pixel(4, green)
        pixels.set_pixel(5, blue)
        pixels.set_pixel(6, violet)
        pixels.set_pixel(7, yellow)
        pixels.set_pixel(8, green)
        pixels.set_pixel(9, blue)
        pixels.set_pixel(10, green)
        pixels.set_pixel(11, orange)
        pixels.set_pixel(12, violet)
        pixels.set_pixel(13, red)
        pixels.set_pixel(14, orange)
        pixels.set_pixel(15, yellow)
        pixels.set_pixel(16, orange)
        pixels.set_pixel(17, red)
        pixels.set_pixel(18, green)
        pixels.set_pixel(19, yellow)
        pixels.set_pixel(20, pink)
        pixels.set_pixel(21, blue)


pixels.set_pixel(0, pink)
pixels.set_pixel(1, blue)
pixels.set_pixel(2, yellow)
pixels.set_pixel(3, orange)
pixels.set_pixel(4, green)
pixels.set_pixel(5, blue)
pixels.set_pixel(6, violet)
pixels.set_pixel(7, yellow)
pixels.set_pixel(8, green)
pixels.set_pixel(9, blue)
pixels.set_pixel(10, green)
pixels.set_pixel(11, orange)
pixels.set_pixel(12, violet)
pixels.set_pixel(13, red)
pixels.set_pixel(14, orange)
pixels.set_pixel(15, yellow)
pixels.set_pixel(16, orange)
pixels.set_pixel(17, red)
pixels.set_pixel(18, green)
pixels.set_pixel(19, yellow)
pixels.set_pixel(20, pink)
pixels.set_pixel(21, blue)
print("app init done\r\n")
while True:
    if motion.value() == 0:
        print("motion detected\r\n")
        mode_sel = mode_sel + 1
        if mode_sel > 10:
            mode_sel =0
        print("mode is %d\r\n", mode_sel)
        time.sleep(1)
    set_mode(mode_sel)
    pixels.show()
    led1.toggle()
    time.sleep(.5)
    print("app toggle\r\n")
    if blink == 1:
        pixels.fill((0,0,0))
        pixels.show()
        time.sleep(.2)
    

Credits

Ashok R

Ashok R

37 projects • 102 followers
Hobbyist/Engineer/Director/Animatior

Comments