in source/cf/defaults/lambdas/sputnik-rpi-sense-hat-demo-python/sense_hat/sense_hat.py [0:0]
def set_pixels(self, pixel_list):
"""
Accepts a list containing 64 smaller lists of [R,G,B] pixels and
updates the LED matrix. R,G,B elements must intergers between 0
and 255
"""
if len(pixel_list) != 64:
raise ValueError('Pixel lists must have 64 elements')
for index, pix in enumerate(pixel_list):
if len(pix) != 3:
raise ValueError('Pixel at index %d is invalid. Pixels must contain 3 elements: Red, Green and Blue' % index)
for element in pix:
if element > 255 or element < 0:
raise ValueError('Pixel at index %d is invalid. Pixel elements must be between 0 and 255' % index)
with open(self._fb_device, 'wb') as f:
map = self._pix_map[self._rotation]
for index, pix in enumerate(pixel_list):
# Two bytes per pixel in fb memory, 16 bit RGB565
f.seek(map[index // 8][index % 8] * 2) # row, column
f.write(self._pack_bin(pix))