Skip to content

Instantly share code, notes, and snippets.

@kurosuke
Last active October 26, 2025 04:06
Show Gist options
  • Select an option

  • Save kurosuke/bfd9f5f19dcf8768c83ccc3cf12ca81c to your computer and use it in GitHub Desktop.

Select an option

Save kurosuke/bfd9f5f19dcf8768c83ccc3cf12ca81c to your computer and use it in GitHub Desktop.
import time, random
import board, neopixel
from digitalio import DigitalInOut, Direction, Pull
# ボタンの設定(GP1をプルアップ)
button = DigitalInOut(board.GP1)
button.direction = Direction.INPUT
button.pull = Pull.UP
num_leds = 5
led_contorol_pin = board.GP0
pixel = neopixel.NeoPixel(
led_contorol_pin, num_leds, brightness=0.4, auto_write=False, pixel_order=neopixel.RGB
)
# RGB = "RGB"
# GRB = "GRB"
# RGBW = "RGBW"
# GRBW = "GRBW"
CLEAR = (0, 0, 0) # clear (or second color)
print("Press the button to light up the LEDs!")
is_black = True
while True:
# ボタンが離されたかチェック(プルアップなので、押されるとFalse)
if button.value:
print("Button release!")
# ボタンがRELEASE(扉が開いた)ので点灯
for i in range(num_leds):
color = (255, 200, 200) # 明るく点灯
pixel[i] = color
pixel.show()
is_black = False
time.sleep(0.5)
# ボタンが押されるるまで待機(扉が閉まるまで)
while button.value:
time.sleep(0.01)
time.sleep(0.1) # デバウンス
else:
# 通常の動作
time.sleep(1)
if not is_black:
for i in range(num_leds):
pixel[i] = CLEAR
pixel.show()
is_black = True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment