From fb45fba6901a6c57e7dc0170ef9098090afdbbae Mon Sep 17 00:00:00 2001 From: L3D Date: Sun, 24 Mar 2024 22:48:05 +0100 Subject: [PATCH] RGB Rainbow --- detect_buzz.py | 0 requirements.txt | 2 ++ rgb_rainbow.py | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+) mode change 100644 => 100755 detect_buzz.py create mode 100755 rgb_rainbow.py diff --git a/detect_buzz.py b/detect_buzz.py old mode 100644 new mode 100755 diff --git a/requirements.txt b/requirements.txt index e9a7937..838f4a3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,3 @@ +RPi.GPIO gpiozero +rpi_ws281x diff --git a/rgb_rainbow.py b/rgb_rainbow.py new file mode 100755 index 0000000..6e8a382 --- /dev/null +++ b/rgb_rainbow.py @@ -0,0 +1,38 @@ +#!/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)