示例#1
0
class MoteLamp(BaseLamp):
    def __init__(self, channels=4, correction=[1., 1., 1.]):

        self.mote = Mote()

        for c in range(channels):
            self.mote.configure_channel(c + 1, 16, False)

        BaseLamp.__init__(self, correction=correction)

        self.channels = channels
        self.pixels = 16

        for channel in range(self.channels):
            self.mote.configure_channel(channel + 1, self.pixels, False)

        self.width = self.channels
        self.height = self.pixels

    # Clear all pixels
    def clear(self):
        self.mote.clear()
        self.mote.show()

    def show(self):
        self.mote.show()

    # Set a single pixel
    def set_pixel(self, x, y, r, g, b):
        r, g, b = self.apply_correction(r, g, b)
        self.mote.set_pixel(x + 1, y, r, g, b)

    # Set all pixels to RGB
    def set_all(self, r, g, b):
        self.color = (r, g, b)
        r, g, b = self.apply_correction(r, g, b)
        self.mote.set_all(r, g, b)

    # Set maximum global brightness
    def set_brightness(self, val):
        val = int(val)
        if 0 <= val <= 255:
            self.mote.set_brightness(
                val / 255)  # Set brightness through unicornhat library
            self.brightness = val  # Log user-selected brightness to a variable
            self.mote.show()
        else:
            logging.error("Brightness must be between 0 and 255")
示例#2
0
tic = 0
toc = 0

# VL53L1X
tof = VL53L1X.VL53L1X(i2c_bus=1, i2c_address=0x29)
tof.open()
tof.start_ranging(
    3)  # Start ranging, 1 = Short Range, 2 = Medium Range, 3 = Long Range

# MOTE
mote = Mote()
mote.configure_channel(1, 16, False)
mote.configure_channel(2, 16, False)
mote.configure_channel(3, 16, False)
mote.configure_channel(4, 16, False)
mote.set_brightness(1)

# OLED
try:
    oled = sh1106(i2c(port=1, address=0x3C), rotate=2, height=128, width=128)
except DeviceNotFoundError:
    print('Did not find 1.12" OLED on 0x3d, trying 0x3d...')
    oled = sh1106(i2c(port=1, address=0x3D), rotate=2, height=128, width=128)


# FUNCTIONS
def exit_handler(signal, frame):
    global running
    running = False
    tof.stop_ranging()  # Stop ranging
    mote.clear()