Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
display module
#1
hello, i have rgb values (as tuple) from color sensor (M5stack)
I can convert these values to hex color string, but display module requires hex color as int and I can't figure how to convert string to int..

hex = "#{:02x}{:02x}{:02x}".format(sensor.read(True)[0],sensor.read(True)[1],sensor.read(True)[2])
print (hex)
0xFF0000
tft.rect(10,10,100,100,0,(hex))

any idea how to convert these rgb values, or use rgb values directly ?

thanks
Reply
#2
(12-28-2018, 08:26 AM)devrosx Wrote: hello, i have rgb values (as tuple) from color sensor (M5stack)
I can convert these values to hex color string, but display module requires hex color as int and I can't figure how to convert string to int..

hex = "#{:02x}{:02x}{:02x}".format(sensor.read(True)[0],sensor.read(True)[1],sensor.read(True)[2])
print (hex)
0xFF0000
tft.rect(10,10,100,100,0,(hex))

any idea how to convert these rgb values, or use rgb values directly ?

thanks

It appears to me you read them as int then your converting it to a string now you want to convet it back to an int. Can't you just use the int without converting it to a sring in the first place??

I assume something like this
24bit_colour = (sensor.read(True)[0] << 16) | (sensor.read(True)[1] << 8) | sensor.read(True)[2]
tft.rect(10,10,100,100, 24bit_colour )
Reply
#3
thanks, looks like my way was unnecessarily complicated Smile
Reply
#4
(12-28-2018, 09:15 AM)OutoftheBOTS Wrote: I assume something like this
24bit_colour = (sensor.read(True)[0] << 16) | (sensor.read(True)[1] << 8) | sensor.read(True)[2]
tft.rect(10,10,100,100, 24bit_colour )

thanks it works now but measurement is quite inaccurate (almost like random color generator Big Grin ), noticed that they have 4 parametr clear color
tried to adjust gain but color recognizing is quite wrong...

here is my code so far


import tcs34725, time
from machine import I2C, Pin
print ('Color detector') 

# angle tcs34725
i2c = I2C(0, sda=21, scl=22)
sensor = tcs34725.TCS34725(i2c)

# LCD
lcd.setBrightness(2)

def mereni(gain=60):
sensor.gain(gain)
(sensor.read(True))
lcd.print('COLOR READ...' + '\n', 15, 130)

lcd.print('checking' + '\n', 5, 140)
bit_colour = (sensor.read(True)[0] << 16) | (sensor.read(True)[1] << 8) | (sensor.read(True)[2])
lcd.print('values: ' + str(sensor.read(True)) + '\n', 5, 160)
lcd.rect(10,10,100,100,0,int(bit_colour))

# actions
def Aclick():
mereni() 
time.sleep_ms(5)

# buttons
buttonA.wasReleased(Aclick)


Reply
#5
OK it is the difference in the resolution of the colour.

The tcs34725 return 16bits red, 16 bits of blue, 16bits of green so it is 48bit colour so 2^48 = 281,474,976,710,656 different colours

The screen is only old school 16bit colour so 2^16 = 65,536 different colours.

Lobo display module takes 24bit colour inputs and converts them down to 16bit colour to display them.

What we have to do is that your 48bit colour and convert it down to 24bit colour to give to the display module then let it convert it down further to 16bit colour. We will do this by copping off the LSB then moving the bits till they r in right place then jioning them together.

something like this

bit_colour = ((sensor.read(True)[0] & 0xff) << 8) | (sensor.read(True)[1] & 0xff) | (sensor.read(True)[2] >> 8)
lcd.print('values: ' + str(sensor.read(True)) + '\n', 5, 160)
lcd.rect(10,10,100,100,0, bit_colour)
Reply
#6
(12-28-2018, 09:24 PM)OutoftheBOTS Wrote: Lobo display module takes 24bit colour inputs and converts them down to 16bit colour to display them.


TFT module actually works with 24-bit colors (the module is initialized in 24-bit mode), unless color_bits argument is set to COLOR_BITS16 in init().
Reply
#7
The color arguments to all module's functions are always 24-bit values (0xRRGGBB). If the display was initiated for 16-bit colors, the color arguments are converted internally (by the function) to 16-bit values.
Reply
#8
thanks for explanation, can we use 32-bit color values also (and then downscaled internally) ? what about direct support for rgb values in some upcoming versions Smile
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)