LED Shim as a thermometer

You would have to create a method to set multiple pixels yourself, it would be based around set_pixel() and might perhaps look something like this:

def set_multiple_pixels(indexes, r, g, b):
    for index in indexes:
        ledshim.set_pixel(index, r, g, b)

Which you could then run with:

set_multiple_pixels(range(0,14), 255, 0, 0)

To set pixels 0 to 13 to red.

You can now use all of the smarts of range() to address different combinations of the available LEDs (0-27), eg every other pixel:

>>> range(0,27,2)
[0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26]

Or just the other side of the display:

>>> range(27,13,-1)
[27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14]

Or every third pixel:

>>> range(0,27,3)
[0, 3, 6, 9, 12, 15, 18, 21, 24]

The set_multiple_pixels function will step through each number in the range, list or tuple supplied and treat it as a pixel index to set.

Going from one set of r, g, b values to another is somewhat more complicated since you need to calculate exactly how you’ll blend them.

You could then expand this function to do colour sweeps like so:

import time
import signal
import ledshim

def set_multiple_pixels(indexes, from_colour, to_colour=None):
    """Set multiple pixels to a range of colours sweeping from from_colour to to_colour

    :param from_colour: A tuple with 3 values representing the red, green and blue of the first colour
    :param to_colour: A tuple with 3 values representing the red, green and blue of the second colour

    """

    if to_colour is None:
        to_colour = from_colour

    length = float(len(indexes))
    step = 0
    from_r, from_g, from_b = from_colour
    to_r, to_g, to_b = to_colour
    step_r, step_g, step_b = to_r - from_r, to_g - from_g, to_b - from_b
    step_r /= length
    step_g /= length
    step_b /= length

    for index in indexes:
        ledshim.set_pixel(index, from_r + (step_r * step), from_g + (step_g * step), from_b + (step_b * step))
        step += 1

# Just green
set_multiple_pixels(range(0,28), (0,255,0))
ledshim.show()
time.sleep(1)

# Sweep from yellow to blue, whee!
set_multiple_pixels(range(0,28), from_colour=(255,255,0), to_colour=(0,0,255))
ledshim.show()
time.sleep(1)

# Half and half
set_multiple_pixels(range(0,14), from_colour=(0,0,255), to_colour=(128,128,255))
set_multiple_pixels(range(14,28), from_colour=(255,0,0), to_colour=(255,255,0))
ledshim.show()

signal.pause()

Heck I should build these functions into ledshim!