I have a BH1745 connected to a Pico W Explorer, displaying it’s readings on the explorers LCD. I also using the Clamped RGB values to light up the LED Ring on an Encoder Wheel.
Sorry about the picture, probably should have turned the LCD Backlight down?
I couldn’t find any info on what the clamped values are? It looks like what ever the highest value is R G or B, that gets clamped to 255, and then the others are adjusted accordingly.
Raw: 451, 849, 896, 1560
Clamped: 128, 241, 255, 1560
Scaled: #4b8b93
Raw: 19, 15, 5, 140
Clamped: 255, 240, 45, 140
Scaled: #1b1d05
Raw: 15, 3, 0, 120
Clamped: 255, 51, 0, 120
Scaled: #280600
That gets me my color on the LER Ring, but at or near full brightness.
import time
import machine
import micropython
import pimoroni_i2c
import breakout_bh1745
PINS_BREAKOUT_GARDEN = {"sda": 4, "scl": 5}
PINS_PICO_EXPLORER = {"sda": 20, "scl": 21}
I2C = pimoroni_i2c.PimoroniI2C(**PINS_PICO_EXPLORER)
bh1745 = breakout_bh1745.BreakoutBH1745(I2C)
bh1745.leds(False)
from picographics import PicoGraphics, DISPLAY_PICO_W_EXPLORER, PEN_P4
from pimoroni import Button
from breakout_encoder_wheel import BreakoutEncoderWheel, UP, DOWN, LEFT, RIGHT, CENTRE, NUM_BUTTONS, NUM_LEDS
wheel = BreakoutEncoderWheel(I2C)
BUTTON_NAMES = ["Up", "Down", "Left", "Right", "Centre"]
last_pressed = [False] * NUM_BUTTONS
pressed = [False] * NUM_BUTTONS
wheel.clear()
button_a = Button(6)
button_b = Button(7)
button_x = Button(10)
button_y = Button(11)
display = PicoGraphics(display=DISPLAY_PICO_W_EXPLORER, pen_type=PEN_P4)
display.set_font("bitmap8")
WHITE = display.create_pen(255, 255, 255)
BLACK = display.create_pen(0, 0, 0)
CYAN = display.create_pen(0, 255, 255)
MAGENTA = display.create_pen(255, 0, 255)
YELLOW = display.create_pen(255, 255, 0)
GREEN = display.create_pen(0, 255, 0)
while True:
rgbc_raw = bh1745.rgbc_raw()
rgb_clamped = bh1745.rgbc_clamped()
rgb_scaled = bh1745.rgbc_scaled()
print("Raw: {}, {}, {}, {}".format(*rgbc_raw))
print("Clamped: {}, {}, {}, {}".format(*rgb_clamped))
print("Scaled: #{:02x}{:02x}{:02x}".format(*rgb_scaled))
display.set_pen(BLACK)
display.clear()
display.set_pen(WHITE)
display.text("Raw: (R, G, B)", 0, 20, scale = 3)
#display.text("{}, {}, {}, {}".format(*rgbl_raw), 0, 50, scale = 3)
display.text("({}, {}, {})".format(*rgbc_raw), 0, 50, scale = 3)
display.text("Clamped: (R, G, B)", 0, 110, scale = 3)
display.text("({}, {}, {})".format(*rgb_clamped), 0, 140, scale = 3)
#display.text("Scaled: {:02x} {:02x} {:02x}".format(*rgb_scaled), 0, 210, scale = 3)
(R, G, B, L) = bh1745.rgbc_clamped()
display.text("Luminance {:0.0f}".format(L), 0, 210, scale = 3)
#print (L)
wheel.clear()
for i in range(NUM_LEDS):
wheel.set_rgb(i, R, G, B)
display.update()
wheel.show()
time.sleep(5.0)
It looks like I’ll have to do some math on the Clamped RGB based on the Luminance / LUX reading. RGB to HSV and use the LUX for V, then do a HSV to RGB?
I have no idea what the Scaled values are?
Looking for suggestions?