Plasma 2350 Neopixel brightness

I have a strip of neopixels attached to my plasma2350w and want to change the brightness. I can do this in circuitpython with a simple command, but I have some code in micropython that I am using and want to adjust the brightness of the neopixels

I have seen an example for the plasma2040 that uses calculations but I want a simple command like brightness = 0.5,

Can you show what code you’re using to light up your neopixels ?

This is the code
Preformatted textimport plasma
from plasma import plasma2040
import time

NUM_LEDS = 60

led_strip = plasma.WS2812(NUM_LEDS, 0, 0, plasma2040.DAT)

led_strip.start()

delay = 0.01

while True:
for i in range(0,NUM_LEDS):
led_strip.set_rgb(i,150,0,0)
time.sleep(delay)
led_strip.set_rgb(i,0,0,0)
time.sleep(delay)

for i in range(NUM_LEDS,0,-1):
    led_strip.set_rgb(i,150,0,0)     
    time.sleep(delay)
    led_strip.set_rgb(i,0,0,0)
    time.sleep(delay)`Preformatted text`

I could rewrite this piece of code in circuitpython but I have other code in micropython that would take time to convert. Plus I prefer micropython.

If you click the Preformatted Text button, the </>, it will wrap your code in code tags and make it easier to view. I had to resort to switching to HSV to get a global brightness function on my plasma 2040. I’m currently running the same code on my Plasma 2350. Changing the V changes the brightness. I can post my code if you want?

This looks like a Pimoroni module object. I will guess that the number 150 is the red pixel brightness on a scale of 0 to 255. Halve the value and check what happens. Set the Green and Blue pixels to a value and again check what happens.

Yes, changing the values will also change brightness, but as a side effect it also changes the color. The HSV-solution of @alphanumeric is better in this case and I would start from his code (@alphanumeric: yes, please post your code).

@dhester: when dealing with brightness, gamma-correction is very important because the brightness-effect is not linear. E.g. changing brightness from 0.1 to 0.2 is totally different compared to changing from 0.4 to 0.5.

CircuitPython has a simple library that does gamma-correction for you. Since most of this code is not CircuitPython specific, it should also work on MicroPython. But maybe you find some MP-specific LED-libs somewhere that do the same job. But first try the HSV approach.

Here is my code. I use an encoder wheel breakout as my controller. Rotating the wheel adjusts the brightness up or down.

import time
import plasma
import machine
import micropython

from plasma import plasma_stick
from pimoroni_i2c import PimoroniI2C
from pimoroni import BREAKOUT_GARDEN_I2C_PINS  # or PICO_EXPLORER_I2C_PINS or HEADER_I2C_PINS
from breakout_encoder_wheel import BreakoutEncoderWheel, UP, DOWN, LEFT, RIGHT, CENTRE, NUM_BUTTONS, NUM_LEDS

BUTTON_NAMES = ["Up", "Down", "Left", "Right", "Centre"]

i2c = PimoroniI2C(plasma_stick.SDA, plasma_stick.SCL)

wheel = BreakoutEncoderWheel(i2c)
#position = 0
last_pressed = [False] * NUM_BUTTONS
pressed = [False] * NUM_BUTTONS

GRB_LEDS = 144

# WS2812 / NeoPixel™ LEDs
led_strip = plasma.WS2812(GRB_LEDS, 0, 0, plasma_stick.DAT, color_order=plasma.COLOR_ORDER_GRB)
led_strip.start()

brightness = (0.5)

red = (1 / 360)
green = (130 / 360)
blue = (250 / 360)
yellow = (60 / 360)
orange = (30 / 360)
white = (1.0)

while True:
    
    # Read all of the encoder wheel's buttons
    for b in range(NUM_BUTTONS):
        pressed[b] = wheel.pressed(b)
        if pressed[b] != last_pressed[b]:
            print(BUTTON_NAMES[b], "Pressed" if pressed[b] else "Released")
        last_pressed[b] = pressed[b]

    if pressed[UP]:
        wheel.clear()
        for i in range(NUM_LEDS):
            wheel.set_hsv(i, 1.0, 0, brightness)
        for s in range(GRB_LEDS):
            led_strip.set_hsv(s, 1.0,  0, brightness)
        wheel.set_hsv(0, 1.0, 0, brightness)
        wheel.set_hsv(6, red, 1.0, brightness)
        wheel.set_hsv(12, green, 1.0, brightness)
        wheel.set_hsv(18, blue, 1.0, brightness)
        color = white

    if pressed[RIGHT]:
        wheel.clear()
        for i in range(NUM_LEDS):
            wheel.set_hsv(i, red, 1.0, brightness)
        for s in range(GRB_LEDS):
            led_strip.set_hsv(s, red,  1.0, brightness) 
        wheel.set_hsv(0, 1.0, 0, brightness)
        wheel.set_hsv(6, red, 1.0, brightness)
        wheel.set_hsv(12, green, 1.0, brightness)
        wheel.set_hsv(18, blue, 1.0, brightness)
        color = red
        
    if pressed[DOWN]:
        wheel.clear()
        for i in range(NUM_LEDS):
            wheel.set_hsv(i, green, 1.0, brightness)
        for s in range(GRB_LEDS):
            led_strip.set_hsv(s, green,  1.0, brightness)
        wheel.set_hsv(0, 1.0, 0, brightness)
        wheel.set_hsv(6, red, 1.0, brightness)
        wheel.set_hsv(12, green, 1.0, brightness)
        wheel.set_hsv(18, blue, 1.0, brightness)
        color = green
        
    if pressed[LEFT]:
        wheel.clear()
        for i in range(NUM_LEDS):
            wheel.set_hsv(i, blue, 1.0, brightness)
        for s in range(GRB_LEDS):
            led_strip.set_hsv(s, blue,  1.0, brightness)         
        wheel.set_hsv(0, 1.0, 0, brightness)
        wheel.set_hsv(6, red, 1.0, brightness)
        wheel.set_hsv(12, green, 1.0, brightness)
        wheel.set_hsv(18, blue, 1.0, brightness)
        color = blue
        
    if pressed[CENTRE]:
        wheel.clear()
        for s in range(GRB_LEDS):
            led_strip.set_hsv(s, 0, 0, 0)              

        
    # Has the dial been turned since the last time we checked?
    change = wheel.delta()
    if change != 0:
        # Print out the direction the dial was turned, and the count
        if change > 0:
            print("Clockwise, Count =", wheel.count())
        else:
            print("Counter Clockwise, Count =", wheel.count())

        # Record the new position (from 0 to 23)
        position = wheel.count()
        '''         
        if position < 1:
            position = 1
            
        if position > 25:
            position = 25
        '''    
        print ("Position =", position)
        
        brightness = ((position + 25) / 50)
        if brightness < 0:
            brightness = 0
            
        if brightness > 1:
            brightness = 1
        
        print ("Brightness =", brightness)
        
        wheel.clear()
        
        if color == white:
            for i in range(NUM_LEDS):
                wheel.set_hsv(i, 1.0, 0, brightness)
            for s in range(GRB_LEDS):
                led_strip.set_hsv(s, 1.0,  0, brightness)         

        else:
            for i in range(NUM_LEDS):
                wheel.set_hsv(i, color, 1.0, brightness)
            for s in range(GRB_LEDS):
                led_strip.set_hsv(s, color,  1.0, brightness)         

        wheel.set_hsv(0, 1.0, 0, brightness)
        wheel.set_hsv(6, red, 1.0, brightness)
        wheel.set_hsv(12, green, 1.0, brightness)
        wheel.set_hsv(18, blue, 1.0, brightness)

    wheel.show()


led_strip.set_rgb(i,150,0,0)

this is the line that you need to change. Put 75 instead of 150 to have 50% brightness. Values must be between 0 and 255. The first number is red, then green, then blue.