Python - Only first led turns off [.turn_off()]

When i use bstick.turn_off() only the first led turns off, how would i go about turning them all off?. 64 leds on channel R

right now i have to open Blinkstick Client 2.0-rc7 and click the all off button :frowning:

1 Like

It seems the python library can not recognize how many LEDs you have connected, so you have to tell it how many LEDs you want to switch off.
Please try this:

cols = [0,0,0,0,0,0,0,0,0]
led.set_led_data(0,cols)

If the first 3 LEDs turning off you could change the code above for your case (64 x 0,0,0).
I hope it helps.

1 Like

You can also try another example:

import time
from blinkstick import blinkstick

class Main(blinkstick.BlinkStickPro):
    def run(self):
        self.send_data_all()
        time.sleep(1)
        self.bstick.set_color(0, 2, 255, 0, 0)
        self.bstick.set_color(0, 4, 255, 255, 0)
        self.bstick.set_color(0, 6, 255, 0, 255)
        time.sleep(1)
        self.off()


# Change the number of LEDs for r_led_count
main = Main(r_led_count=1, max_rgb_value=128)
if main.connect():
    main.run()
else:
    print "No BlinkSticks found"

self.send_data_all() should also switch off all your LEDs.

nothing worked even tried
import time
import math
import colorsys
from random import randint

from blinkstick import blinkstick

shaun = blinkstick.find_first()

cols = [0,0,0,0,0,0,0,0,0]
shaun.set_data(0,cols)

I got the following code working BUT it only turns off the leds that are static and wont keep a chase light pattern off. in other words the chase script keeps executing

import colorsys
from random import randint

from blinkstick import blinkstick

shaun = blinkstick.find_first()

shaun.set_color(channel=0, index=0, name=“black”)
shaun.set_color(channel=0, index=1, name=“black”)
etc etc

How have you realized the chase light? Could it be possible that your sequence still running if you try to switch off all LEDs? Maybe you could post the code of how you have realized your chase light.

import time
import math
import colorsys
from random import randint

from blinkstick import blinkstick

class Main(blinkstick.BlinkStickPro):
def run(self):
self.send_data_all()

    green = randint(0, 255)

    x = 0
    sign = 1
    try:
        while True:
            self.bstick.set_color(0, x, 0, green)
            time.sleep(0.02)
            self.bstick.set_color(0, x, 0, 0, 0)
            time.sleep(0.004)

            x += sign
            if x == self.r_led_count - 1:
                sign = -1
                green = randint(0, 255)

            elif x == 0:
                sign = 1


    except KeyboardInterrupt:
        self.off()
        return

main = Main(r_led_count=64, max_rgb_value=128)
if main.connect():
main.run()
else:
print “No BlinkSticks found”

Did this in Visual Basic and it turns off the leds

Private Sub Button10_Click(sender As Object, e As EventArgs) Handles Button10.Click
Shell(“cmd.exe /c TASKKILL /IM python.exe /F”)
Shell(“C:\Python27\python.exe alloff.py arg1 arg2”, AppWinStyle.Hide)
End Sub

If you have to kill the whole python task, your sequence (endless loop) is still running. You cannot switch off your LEDs if another instance switches the LEDs frequently on again…
So what you have to do is find a way to stop the sequence first (keyboard interrupt or so) to control the LEDs from another instance again.

1 Like