Page 1 of 1

[Python] Define how many pixels to light

Posted: Sun May 19, 2019 2:37 pm
by user7743
Hi all,
Can someone give me a pointer here. I have a sense-hat and I want to be able to give a number between 1 and 64, and then light the corresponding number of pixels in a given colour. How can I programatically do that in Python?
Thanks in advance.

Re: [Python] Define how many pixels to light

Posted: Sun May 19, 2019 2:49 pm
by B.Goode
user7743 wrote:
Sun May 19, 2019 2:37 pm
Hi all,
Can someone give me a pointer here. I have a sense-hat and I want to be able to give a number between 1 and 64, and then light the corresponding number of pixels in a given colour. How can I programatically do that in Python?
Thanks in advance.


The Raspberry Pi Foundation project about Getting started with the Sense Hat has a section that deals with setting individual and multiple pixels. https://projects.raspberrypi.org/en/pro ... ense-hat/6

The documentation for the supporting Python library is here:https://pythonhosted.org/sense-hat/

Re: [Python] Define how many pixels to light

Posted: Mon May 20, 2019 3:13 pm
by user7743
After thinking about this a bit more I got to the point I wanted. Simple when I thought about it...

Code: Select all

pixels = []
for i in range(64):
    if i < pixelCount:
        pixels.append(RED)
    else:
        pixels.append(CLEAR)
sense.set_pixels(pixels)