astro-pi / python-sense-hat

Source code for Sense HAT Python library
https://sense-hat.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
507 stars 255 forks source link

Doing Maths with Pixel Values #104

Closed rowena-s closed 3 years ago

rowena-s commented 3 years ago

I have a design for the LED array where I want to slowly pulse the lights by increasing and decreasing intensity of specific pixels. However, when I get the values with get_pixel() it seems to always be less than what it should actually be.

sense.set_pixel(4,0,[255,255,0])
r,g,b = sense.get_pixel(4,0)
print(r,g,b) # shows 248 252 0 when it should be 255 255 0

r1 = r-20
g1 = g-20
print(r1,g1,b) # shows 228, 232, 0 which is correct from the actual values

sense.set_pixel(4,0,[r1,g1,b])
print(sense.get_pixel(4,0)) #  shows me 224, 232, 0

Is there a way to achieve what I want given I can't rely on getting back the correct pixel values?

bsimmo commented 3 years ago

What you are seeing is correct.

Use a variable(s) in your program to store the values and always use that rather than using the led itself.

On Sat, 12 Dec 2020, 5:46 am rowena-s, notifications@github.com wrote:

I have a design for the LED array where I want to slowly pulse the lights by increasing and decreasing intensity of specific pixels. However, when I get the values with get_pixel() it seems to always be less than what it should actually be. ` sense.set_pixel(4,0,[255,255,0]) r,g,b = sense.get_pixel(4,0) print(r,g,b) # shows 248 252 0 when it should be 255 255 0

r1 = r-20 g1 = g-20 print(r1,g1,b) # shows 228, 232, 0 which is correct from the actual values

sense.set_pixel(4,0,[r1,g1,b]) print(sense.get_pixel(4,0)) # shows me 224, 232, 0 `

Is there a way to achieve what I want given I can't rely on getting back the correct pixel values?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/astro-pi/python-sense-hat/issues/104, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACYAXNZ6EF6QRLA7SRCKGVLSUL7S3ANCNFSM4UXXSGEQ .

rowena-s commented 3 years ago

ah, thanks!

bsimmo commented 3 years ago

Bit more time now, but there is a short explanation of what you were seeing on the API Reference - Sense HAT (pythonhosted.org) https://pythonhosted.org/sense-hat/api/#led-matrix page, look down to getpixels()

On Sat, 12 Dec 2020 at 08:17, rowena-s notifications@github.com wrote:

ah, thanks!

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/astro-pi/python-sense-hat/issues/104#issuecomment-743722469, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACYAXN3WLUHKUWZWVWQN4ELSUMRKNANCNFSM4UXXSGEQ .

rowena-s commented 3 years ago

ohhh, I looked at getpixel() - singular, and missed the note at the bottom that says to check the note under the plural version.