import time
from rpi_ws281x import *

# LED strip configuration
LED_COUNT = 22
LED_PIN = 18  # GPIO pin for the LED strip (BCM pin number)
LED_FREQ_HZ = 800000  # LED signal frequency in Hz (usually 800kHz)
LED_DMA = 10  # DMA channel to use for generating signal
LED_BRIGHTNESS = 255  # Set the brightness of the LED (0 to 255)
LED_INVERT = False  # True to invert the signal (when using NPN transistor level shift)
LED_CHANNEL = 0  # Set to 0 for GPIOs 13, 19, 41, 45, 53; set to 1 for GPIOs 12, 18, 40, 52

# Create PixelStrip object
strip = Adafruit_NeoPixel(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT, LED_BRIGHTNESS, LED_CHANNEL)
strip.begin()

def turn_on_led(led_number):
    # Check if the given LED number is within the valid range
    if led_number < 0 or led_number >= LED_COUNT:
        print("Invalid LED number")
        return
    
    # Turn on the specified LED
    strip.setPixelColor(led_number, Color(255, 255, 255))  # Set the color of the LED (in RGB format)
    strip.show()

# Example usage
target_led = 1  # LED number to turn on (0 to LED_COUNT-1)
turn_on_led(target_led)

# Wait for a few seconds to observe the LED
time.sleep(5)

# Turn off the LED
strip.setPixelColor(target_led, Color(0, 0, 0))
strip.show()
