import time
from machine import Pin
import neopixel
# Define the number of LEDs in your strip
num_pixels = 18
# Initialize the neopixel object
neo_di = machine.Pin(27) # GPIO pin connected to the data input of the LED strip
np = neopixel.NeoPixel(neo_di, num_pixels)
np2 = neopixel.NeoPixel(machine.Pin(26), num_pixels)
# Function to set the LEDs to red
def set_red():
for i in range(num_pixels):
np[i] = (255, 0, 0) # Red color
np2[i] = (255, 0, 0) # Red color
np.write()
np2.write()
# Function to set the LEDs to green
def set_green():
for i in range(num_pixels):
np[i] = (0, 255, 0) # Green color
np2[i] = (0, 255, 0) # Green color
np.write()
np2.write()
# Create LED objects for onboard LED (GPIO 25) and external LEDs (GPIO 13, 14, 15)
onboard_led = Pin(11, Pin.OUT)
external_led1 = Pin(10, Pin.OUT)
external_led2 = Pin(9, Pin.OUT)
external_led3 = Pin(8, Pin.OUT)
# Create PIN objects to check for a signal from the switch
slideswitch = Pin(18, Pin.OUT)
receiver = Pin(19, Pin.IN)
# Function to toggle the LEDs
def toggle_leds():
onboard_led.toggle()
external_led1.toggle()
external_led2.toggle()
external_led3.toggle()
#Check the switchand change the colour if in the forward position
def colour_switch():
if(receiver = HIGH):
set_red
else:
set_green
# Main loop: Blink the LEDs
while True:
toggle_leds()
time.sleep(0.5) # Delay in seconds (adjust as needed)
set_green()
time.sleep(.5) # Wait for 1 second