from machine import Pin, I2C
import time
import neopixel
led = machine.Pin("LED", machine.Pin.OUT)
button = machine.Pin(4, machine.Pin.IN, machine.Pin.PULL_UP)
sensor_pin = 26
sensor = Pin(sensor_pin, Pin.IN)
pixPin = 10 # Numper of pin
pixSize = 10 # How many LEDs
pix = neopixel.NeoPixel(Pin(pixPin), pixSize) # Initialization
blue = (0,0,255)
off = (0,0,0)
# Initialize state variables
state = 0
val = 0
while True:
val = button.value()
if not val:
state = not state
if state:
led.high()
while state:
led.high()
motion = sensor.value()
if motion:
for i in range(2):
pix[i] = blue
pix.write()
time.sleep(1)
pix[i] = off
pix.write()
time.sleep(1)
led.low()
time.sleep(0.1)