Example #1
0
class Driver:

    def __init__(self):
        self.pwm = PWM()
        self.pwm.setPWMFreq(1000)

    def checkRGB(self, r, g, b):
        if r < 0 or r > 255:
            return False
        if g < 0 or g > 255:
            return False
        if b < 0 or b > 255:
            return False
        return True


    def setRGB(self, strip, r, g, b):
        if self.checkRGB(r, g, b) == False:
            raise Exception("{0}, {1}, {2} is an invalid RGB value".format(r,g,b))

        offset = strip * 3

        self.pwm.setPWM(offset, 0, r * SCALAR)
        self.pwm.setPWM(offset+1, 0, g * SCALAR)
        self.pwm.setPWM(offset+2, 0, b * SCALAR)

    def fade_step(self, light, increment, value, color):
        if increment == True:
            value = value + 0.01
            if value >= 1.0:
                increment = False
        else:
            value = value - 0.01
            if value <= 0:
                increment = True
        r,g,b = ledcolors.hsv2rgb(color['h'], color['s'], value)
        self.setRGB(light, r, g, b)
        return increment, value

    def fade_all_colors_step(self, light, value, color):
        value = value + 1;
        r,g,b = ledcolors.hsv2rgb(value % 360, 1.0, 1.0)
        self.setRGB(light, r, g, b)
        return value + 1

    def blink_led(self, light, on, color):
        if on:
            value = 0.0
        else:
            value = 1.0
        r,g,b = ledcolors.hsv2rgb(color['h'], color['s'], value)
        self.setRGB(light, r, g, b)
        return not on

    def blink_all_colors(self, light, on, color):
        r,g,b = ledcolors.hsv2rgb(color, 1.0, 1.0)
        self.setRGB(light, r, g, b)
        return not on, ((color + 50) % 360)
Example #2
0
 def __init__(self):
     self.pwm = PWM()
     self.pwm.setPWMFreq(1000)