Python Output - Blinking Seperate Neopixels

problem: how to code Python in Node Red output to blink separate Neopixels

I have the following output to a .py file, which is run by a crontab at certain intervals. Currently, lighting works perfect and all leds are behaving as they should. I would like to set an individual pixel to 'blink' if a condition is met and change the output of the Node Red Python file. I'm thinking I have to 'wrap' each pixel in some kind of loop command. Ideas?



I would like pixel[29] to blink, while pixel[25] stays solid.


Are you blinking the LED with python(3) or Node-Red?

If it is python(3) it shouldn't be hard.

Looking at the lines I can't remember if that is right.
I have a machine with NeoPixels but it is kind of out of order just now. :frowning: I can't power it up to look at my code.

How many LED's on the strip?

I can post a SIMILAR script I have for LEDs. But they are NOT NeoPixels. They are a similar family and are like NeoPixels.

I ca post THAT one if you want.
It - the script - MAY give you an idea of what to do.

Thanks for reply. I am using Node Red to build the Python file, which will blink the LEDS. Any sample code may help. Total number of LEDS, about 25. Of which, any number could/may be called to blink, or not.

Well if there are 25 LEDs the command pixels[29]=(0,0,255) is going to be problematic.

Hang on I'm knee keep in problems just now.

I'll post the code ASAP.

The code:

(Other people helped me)


import time
import sys
import paho.mqtt.client as mqtt
import blinkt


def on_connect(client, userdata, flags, rc):
    print("Connected:", rc)
    client.subscribe("TELEPI_LOCAL/tele_led/#", 0)

def on_subscribe(client, userdata, mid, granted_qos):
    print ('Subscribed:', userdata, mid, granted_qos)
    print ('We are here, waiting for commands...')

def on_message(client, userdata, msg):

    global abort
    global blinkt
    print ("===============================")
    print ("New loop invocation")
    my_string = (msg.payload.decode("utf-8"))
    #my_string = (message.payload.decode("utf-8"))
    print ("my_String")
    print (my_string)
    dummy = my_string.split(",")
    print ("Dummy ",dummy)

#   [int(x) & 0xff for x in data]
    command = dummy[0]
    print ("Command ",command)

    if command == 'Heartbeat':
        print ("I am alive")
        client.publish("TELEPI_LOCAL/tele_led/led-response", "Script is alive")

    if command == 'Stop':
        print ("Script terminates..")
        client.publish("TELEPI_LOCAL/tele_led/led-response", "Script is stopping")
        blinkt.set_all(0, 0, 0)
        abort = True

    print (len(dummy))

    if command == 'rgb' and len(dummy) == 5:
        pixel = dummy[1]
        red = dummy[2]
        green = dummy[3]
        blue = dummy[4]

        pixel = int(pixel)
        if pixel > 8: pixel = 0
        red = int(red)
        green = int(green)
        blue = int(blue)

        print("--==  values  ==--")
        print ("Command >",command,"<")
        print ("LED ", pixel)
        print ("Red ", red)
        print ("Green ",green)
        print ("Blue ",blue)

        print ("Data length ",len(dummy))

        if pixel == 8:
            print ("Oops")

#            for x in range(blinkt.NUM_PIXELS):
#                blinkt.set_pixel(pixel,red,greed,blue)
            print ("setting pixel")
            print ("Led ",pixel," Red ",red," Green ",green," Blue ",blue)
#    if command == "dim":

# inits
#mqtt_broker = ""
mqtt_broker = ""
mqtt_port = 1883
abort = False
#client = mqtt.Mosquitto()
client = mqtt.Client("LED blink routine")
client.on_connect = on_connect
client.on_message = on_message
client.on_subscribe = on_subscribe
resp = client.connect(mqtt_broker, mqtt_port, 60)

while abort == False:

del client
print ('Script has terminated')

Let me know if you need help on it.

SORRY, I posted the wrong code.


Look again!

1 Like

Thanks, I'll give it a look over.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.