# Path: IoTPy/things/led_strip.py
# class LedStrip:
# 
#     def __init__(self, spi):
#         self.spi = spi
# 
#         self.set_color(0)
# 
#     def __enter__(self):
#         return self
# 
#     def __exit__(self, exc_type, exc_value, traceback):
#         pass
# 
#     def set_colors(self, colors):
#         data = "\x00\x00\x00\x00"
# 
#         for color in colors:
#             r = color >> 19 & 0x1F
#             g = color >> 11 & 0x1F
#             b = color & 0x1F
#             tmp = 0x8000 | (b << 10) | (r << 5) | g
#             data += chr(tmp >> 8) + chr(tmp & 0xFF)
# 
#         for i in xrange((len(colors)+7)/8):
#             data += '\x00'
# 
#         self.spi.write(data)
# 
#     def set_color(self, color):
#         self.set_colors([color] * 50)


from time import sleep
from IoTPy.ioboard.boards.uper import UPER1
from IoTPy.things.led_strip import LedStrip



def shift(seq, n):
    n %= len(seq)
    return seq[n:] + seq[:n]

with UPER1() as board, board.spi("SPI0", clock=2.9e6) as spi, LedStrip(spi) as leds:

# Path: IoTPy/things/led_strip.py
# class LedStrip:
# 
#     def __init__(self, spi):
#         self.spi = spi
# 
#         self.set_color(0)
# 
#     def __enter__(self):
#         return self
# 
#     def __exit__(self, exc_type, exc_value, traceback):
#         pass
# 
#     def set_colors(self, colors):
#         data = "\x00\x00\x00\x00"
# 
#         for color in colors:
#             r = color >> 19 & 0x1F
#             g = color >> 11 & 0x1F
#             b = color & 0x1F
#             tmp = 0x8000 | (b << 10) | (r << 5) | g
#             data += chr(tmp >> 8) + chr(tmp & 0xFF)
# 
#         for i in xrange((len(colors)+7)/8):
#             data += '\x00'
# 
#         self.spi.write(data)
# 
#     def set_color(self, color):
#         self.set_colors([color] * 50)


# Path: examples/sensors/08_LedStrip.py
from time import sleep
from IoTPy.ioboard.boards.uper import UPER1
from IoTPy.things.led_strip import LedStrip




def shift(seq, n):
    n %= len(seq)
    return seq[n:] + seq[:n]

with UPER1() as board, board.spi("SPI0", clock=2.9e6) as spi, LedStrip(spi) as leds:

    colors = [0xFF0000, 0xFFFF00, 0x00FF00, 0x0000FF, 0xFF00FF]