Interstate 74 W, how do you control the display brightness?

I was wanting to code up an auto brightness function on my Interstate 75 W. But looking at the Function Reference, I’m not seeing any backlight / display brightness function?
I have an LTR-559 wired up and working, just need a way to control the array brightness?

I’m running two 64x32 panels in a 128 x 32 array with Pimoroni’s custom uf2 file. Pico Graphics.

Daft question:

Have you tried using the picographics command display.set_backlight()

I don’t own one of these boards, so unable to test myself.

Not yet, I’ll likely get an error and I’d have to change all the “graphics” references to “display”.
I’ll likely give it a go sometime today, was waiting to see if there was an easier way.
Or if how its done just didn’t get documented.
@hel @gadgetoid

import time
import machine
from interstate75 import Interstate75
from interstate75 import Interstate75, SWITCH_A, SWITCH_B
i75 = Interstate75(display=Interstate75.DISPLAY_INTERSTATE75_128X32)

graphics = i75.display
#graphics.set_font("bitmap")
graphics.set_font("bitmap8")
#graphics.set_font("bitmap16")

#graphics.set_font("8x12")
#graphics.set_font("10x14")

t_color = graphics.create_pen(0,0,0)
h_color = graphics.create_pen(0,0,0)
p_color = graphics.create_pen(0,0,0)

black = graphics.create_pen(0,0,0)
red = graphics.create_pen(255,0,0)
green = graphics.create_pen(0,255,0)
blue = graphics.create_pen(0,0,255)
yellow = graphics.create_pen(255,255,0)
orange = graphics.create_pen(255,140,0)
white = graphics.create_pen(255,255,255) 
clock = graphics.create_pen(222,222,222)

graphics.set_pen(black)
graphics.clear()
i75.update(graphics)
i75.set_led(0, 0 ,0)

from breakout_bme68x import BreakoutBME68X, STATUS_HEATER_STABLE
#from breakout_bme280 import BreakoutBME280
from pimoroni_i2c import PimoroniI2C

i2c = PimoroniI2C(sda=(20), scl=(21))
bme = BreakoutBME68X(i2c)
temperature, pressure, humidity, gas, status, _, _ = bme.read()
#bme = BreakoutBME280(i2c, 0x76)
#temperature, pressure, humidity = bme.read()

from breakout_rtc import BreakoutRTC
from machine import RTC
RV3028 = BreakoutRTC(i2c)

rtc = BreakoutRTC(i2c)
if rtc.is_12_hour:
    rtc.set_24_hour()
    
RV3028.update_time()
hour = rtc.get_hours()
minute = rtc.get_minutes()
month = rtc.get_month()
date = rtc.get_date()    
     
if rtc.read_periodic_update_interrupt_flag():
    rtc.clear_periodic_update_interrupt_flag()

if rtc.update_time():
    rtc_date = rtc.string_date()
    rtc_time = rtc.string_time()    


#temperature, pressure, humidity = bme.read()
temperature, pressure, humidity, gas, status, _, _ = bme.read()
time.sleep (0.5)

start_time = time.time()

while True:
    graphics.set_pen(black)
    graphics.clear()
    i75.update(graphics)
    
    time_elapsed = time.time() - start_time
    RV3028.update_time()
    hour = rtc.get_hours()
    minute = rtc.get_minutes()
    month = rtc.get_month()
    date = rtc.get_date()    
     
    if rtc.read_periodic_update_interrupt_flag():
        rtc.clear_periodic_update_interrupt_flag()

    if rtc.update_time():
        rtc_date = rtc.string_date()
        rtc_time = rtc.string_time()
    #year, month, day, wd, hour, minute, second, _ = rtc.datetime()    
    
    graphics.set_pen(clock)
   
    if hour == 0:
        graphics.text(f"{12}:{minute:02}AM", 1, 1, scale=2)    
    elif 0 <= hour < 10:
        graphics.text(f"{hour:1}:{minute:02}AM", 7, 1, scale=2)
    elif 10 <= hour < 12:
        graphics.text(f"{hour:2}:{minute:02}AM", 1, 1, scale=2)
    elif hour == 12:
        graphics.text(f"{hour:2}:{minute:02}PM", 1, 1, scale=2)    
    elif hour > 12:
        hour = hour - 12
        if hour < 10:
            graphics.text(f"{hour:1}:{minute:02}PM", 7, 1, scale=2)
        elif 10 <= hour < 12:
            graphics.text(f"{hour:2}:{minute:02}PM", 1, 1, scale=2)
        elif hour == 12:
            graphics.text(f"{hour:2}:{minute:02}AM", 1, 1, scale=2)        
        
    #temperature, pressure, humidity = bme.read()
    temperature, pressure, humidity, gas, status, _, _ = bme.read()        
    
    temperature = round(temperature)

    if temperature < -10:
        t_color = white
    elif -10 <= temperature <= 0:
        t_color = blue
    elif 0 < temperature <= 12:
        t_color = yellow
    elif 12 < temperature <= 16:
        t_color = green
    elif 16 < temperature <= 24:
        t_color = green      
    elif 24 < temperature <= 27:
        t_color = orange
    elif temperature > 27:
        t_color = red

    graphics.set_pen(t_color)
    if temperature > 0:
        graphics.text("+{:0.0f}°C" .format(temperature), 10, 17, scale=2)
    else:    
        graphics.text("{:0.0f}°C" .format(temperature), 15, 17, scale=2)
    
    humidity = round(humidity)   

    if humidity < 30:
        h_color = red
    elif 30 <= humidity <= 60:
        h_color = green
    elif 60 < humidity < 80:
        h_color = yellow
    elif humidity >= 80:
        h_color = orange        

    graphics.set_pen(h_color)
    graphics.text("{:0.0f}% RH".format(humidity), 69, 1, scale=2)

    pressuremb = pressure / 100           
    pressuremb = round(pressuremb)
    
    if pressuremb < 982:
        p_color = red
    elif 982 <= pressuremb < 1004:
        p_color = yellow
    elif 1004 <= pressuremb < 1026:
        p_color = green
    elif 1026 <= pressuremb < 1048:
        p_color = blue
    elif pressuremb >= 1048:
        p_color = orange
 
    graphics.set_pen(p_color)
    graphics.text("{:0.0f}mb" .format(pressuremb), 67, 17, scale=2)

    i75.update(graphics)
    time.sleep (30)

I got a “display not defined” error.
Edited all the “graphics” references to “display”
No errors but it has no effect on the brightness.

I’m thinking I’d have to do some fancy hsv stuff?
Way above my skill level though.

I think set.backlight() will only do anything on LCD displays.

I don’t think there’s a global set_brightness() for Interstate like there is with the Unicorns. I’d probably get round this by setting up my colours as HSV pens:

graphics.create_pen_hsv(h, s, v)

If you set up a brightness variable for using as your ‘value’, you can adjust that elsewhere in your program based on the light level or whatever - this would be half brightness red, for example:

brightness = 0.5

MURKY_RED = graphics.create_pen_hsv(1.0, 1.0, brightness)

You could also adjust the brightness the old school way, by dialing down the RGB values. This way might a bit less straightforward to adjust globally though:

MURKY_RED = graphics.create_pen(125, 0, 0)

I was afraid that would be the case. =( Very frustrating if I’m honest.
Not sure I’m going bother trying. I say that but I probably will at some point. I’m stubborn that way.
So far the Interstate 75 has been a big disappointment function wise. I can’t set my array the way I want, so I have to do all kinds of positioning adjustments just to display text where I want it. And now another big code edit just to get a brightness function?

There could be a hardware reason why we don’t have a global brightness function for Interstate 75 (I know the LEDs are quite different) but if it’s something you’d find useful you could suggest it as a feature:

Is there a reference somewhere as to what number is what color?
RED = graphics.create_pen_hsv(1.0, 1.0, brightness)
GREEN = graphics.create_pen_hsv(?, ?, brightness)
BLUE = etc?

Our Gadgetoid did a good intro to HSV (Hue Saturation Value) back in the day if you’ve not come across it before :)

For finding out the hue of specific colours, try this colour wheel picker - Reinvented Color Wheel Picker Demo Page

Note that most colour pickers will give you a hue as a number between 0-360 degrees (that’s the position of the colour on the colour wheel) and you’ll need to give our create_pen_hsv function a value between 0.0 and 1.0

I tend to do something like:

graphics.create_pen_hsv(hue / 360, saturation, brightness)

so green would be:

brightness = 0.5

MURKY_GREEN = graphics.create_pen_hsv(130 / 360, 1.0, brightness)
1 Like

Ok, thanks for that will have a look see, and likely have a go at trying some code on my setup.

1 Like

@hel ,that helped tremendously. It appears I was making a mountain out of a mole hill. Apologies for that as it wasn’t near as hard as I thought it was going to be. Not once you have some good info on how it works. I’ll post my working code once I tidy it up.

I still have to do some code for the LTR-559, but changing the “brightness =” is adjusting the brightness so I’m marking this as solved.

1 Like

This seems to be doing what I want. Will have to see what it looks like in low light conditions and maybe tweak some of the numbers. Back and neck are getting sore so calling it quits for now. I’ll strip the junk out latter on and post the condensed version.

import time
import machine
import micropython

from interstate75 import Interstate75
from interstate75 import Interstate75, SWITCH_A, SWITCH_B
i75 = Interstate75(display=Interstate75.DISPLAY_INTERSTATE75_128X32)

graphics = i75.display
graphics.set_font("bitmap8")

BACKLIGHT_LOW = micropython.const(0.35)
BACKLIGHT_HIGH = micropython.const(1.0)

LUMINANCE_LOW = micropython.const(256)
LUMINANCE_HIGH = micropython.const(2048)  

brightness = (1.0)

black = graphics.create_pen_hsv(0, 0, 0)
red = graphics.create_pen_hsv(1 / 360, 1.0, brightness)
green = graphics.create_pen_hsv(130 / 360, 1.0, brightness)
blue = graphics.create_pen_hsv(250 / 360, 1.0, brightness)
yellow = graphics.create_pen_hsv(60 / 360, 1.0, brightness)
orange = graphics.create_pen_hsv(30 / 360, 1.0, brightness)
white = graphics.create_pen_hsv(1.0, 0, brightness)

graphics.set_pen(black)
graphics.clear()
i75.update(graphics)
i75.set_led(0, 0 ,0)

from pimoroni_i2c import PimoroniI2C
i2c = PimoroniI2C(sda=(20), scl=(21))

from breakout_ltr559 import BreakoutLTR559
ltr = BreakoutLTR559(i2c)
part_id = ltr.part_id()
print("Found LTR559. Part ID: 0x", '{:02x}'.format(part_id), sep="")

def auto_brightness(previous: float) -> (float, float):
    luminance = reading[BreakoutLTR559.LUX]
    luminance_frac = max(0.0, float(luminance - LUMINANCE_LOW))
    luminance_frac = min(1.0, luminance_frac / (LUMINANCE_HIGH - LUMINANCE_LOW))
    backlight = BACKLIGHT_LOW + (luminance_frac * (BACKLIGHT_HIGH - BACKLIGHT_LOW))
    # Use the previous value to smooth out changes to reduce flickering.
    # The "32" value here controls how quickly it reacts (larger = slower).
    # The rate at which the main loop calls us also affects that!
    backlight_diff = backlight - previous
    backlight = previous + (backlight_diff * (1.0 / 32.0))
    return (luminance, backlight)

backlight = BACKLIGHT_LOW
start_time = time.time()

while True:
    
    reading = ltr.get_reading()
    if reading is not None:
        print("Lux:", reading[BreakoutLTR559.LUX], "Prox:", reading[BreakoutLTR559.PROXIMITY])

    lux = reading[BreakoutLTR559.LUX]

    (luminance, backlight) = auto_brightness(backlight)
    
    time.sleep(0.1)    
 
    brightness = backlight
    print (brightness)
    
    black = graphics.create_pen_hsv(0, 0, 0)
    red = graphics.create_pen_hsv(1 / 360, 1.0, brightness)
    green = graphics.create_pen_hsv(130 / 360, 1.0, brightness)
    blue = graphics.create_pen_hsv(250 / 360, 1.0, brightness)
    yellow = graphics.create_pen_hsv(60 / 360, 1.0, brightness)
    orange = graphics.create_pen_hsv(30 / 360, 1.0, brightness)
    white = graphics.create_pen_hsv(1.0, 0, brightness)
    
    graphics.set_pen(black)
    graphics.clear()
    i75.update(graphics)

    time.sleep (1)

1 Like

Good stuff, HSV is well worth getting your head around - it’s particularly useful for when you want to shift through a range of colours or make rainbows :)

I reckon a global brightness setting might still be a good addition - adjusting the pen colour works for text and shapes but I can’t think of a way of adjusting the brightness of images…

1 Like