rpi_zero_neopixel_buzzer/rgb_rainbow.py
2024-03-24 22:48:05 +01:00

38 lines
1.1 KiB
Python
Executable file

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Example RGB to Neopixel LED
"""
from rpi_ws281x import Adafruit_NeoPixel, Color
# NeoPixel configuration
PIN_NEO_PIXEL = 18
NUM_PIXELS = 24
DELAY_INTERVAL = 50
# Create NeoPixel object
NeoPixel = Adafruit_NeoPixel(NUM_PIXELS, PIN_NEO_PIXEL)
NeoPixel.begin() # Initialize NeoPixel strip object
try:
while True:
# Turn on all pixels to green
for pixel in range(NUM_PIXELS):
NeoPixel.setPixelColor(pixel, Color(0, 255, 0))
NeoPixel.show()
time.sleep(DELAY_INTERVAL / 1000.0)
time.sleep(2)
# Turn on all pixels to red
for pixel in range(NUM_PIXELS):
NeoPixel.setPixelColor(pixel, Color(255, 0, 0))
NeoPixel.show()
time.sleep(DELAY_INTERVAL / 1000.0)
time.sleep(2)
except KeyboardInterrupt:
# Clean up code before exiting the script
for pixel in range(NUM_PIXELS):
NeoPixel.setPixelColor(pixel, Color(0, 0, 0))
NeoPixel.show()
time.sleep(DELAY_INTERVAL / 1000.0)