## [Python] Define how many pixels to light

user7743
Posts: 6
Joined: Fri Jan 13, 2012 10:02 am

### [Python] Define how many pixels to light

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.

B.Goode
Posts: 7868
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

### Re: [Python] Define how many pixels to light

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/

user7743
Posts: 6
Joined: Fri Jan 13, 2012 10:02 am

### Re: [Python] Define how many pixels to light

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)``````

Return to “Astro Pi”