示例#1
0
class Worker(QObject):
    finished=pyqtSignal()

    def __init__(self, parent=None, **kwargs):
        super (Worker, self).__init__(parent, **kwargs)

        self._stop=False
        self._scheme=0
        self._pattern=0
        self._width=0
        self._speed=0

	self._neoPixel=NeoPixel(24)
        self._neoPixel.setBrightness(.4)

    @pyqtSlot()
    def work(self):
        if self._stop:
            self._neoPixel.clear()
            self._neoPixel.show()
            self.finished.emit()
            return    

        scheme=schemes[self._scheme]
        speed=speedValues[self._speed]

        if self._pattern==BARS:
            self._neoPixel.bars(scheme, barWidthValues[self._width], speed)        
        elif self._pattern==GRADIENT:
            self._neoPixel.gradient(scheme, gradientWidthValues[self._width], speed)

        QTimer.singleShot(10, self.work)

    @pyqtSlot(int)
    def setScheme(self, scheme): self._scheme=scheme

    @pyqtSlot(int)
    def setPattern(self, pattern): self._pattern=pattern

    @pyqtSlot(int)
    def setWidth(self, width): self._width=width

    @pyqtSlot(int)
    def setSpeed(self, speed): self._speed=speed

    @pyqtSlot()
    def stop(self): self._stop=True
示例#2
0
# ==========                                                                  #
# A C++ library for driving WS2812 RGB LED's (known as 'NeoPixels' by         #
#     Adafruit) directly from a Raspberry Pi with accompanying Python wrapper #
# Copyright (C) 2014 Rob Kent                                                 #
#                                                                             #
# This program is free software: you can redistribute it and/or modify        #
# it under the terms of the GNU General Public License as published by        #
# the Free Software Foundation, either version 3 of the License, or           #
# (at your option) any later version.                                         #
#                                                                             #
# This program is distributed in the hope that it will be useful,             #
# but WITHOUT ANY WARRANTY; without even the implied warranty of              #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               #
# GNU General Public License for more details.                                #
#                                                                             #
# You should have received a copy of the GNU General Public License           #
# along with this program.  If not, see <http://www.gnu.org/licenses/>.       #
#                                                                             #
###############################################################################

from NeoPixel import NeoPixel

if __name__ == "__main__":
    n = NeoPixel(60)
    n.setBrightness(1.)
    n.effectsDemo()
    n.clear()
    n.show()
    del n
    exit(0)
示例#3
0
    if b < 0:
        b = 0
    c = Color()
    c.r = int(r * 255)
    c.g = int(g * 255)
    c.b = int(b * 255)
    return c


# Creates a rainbow of all colors across all leds
# The rainbow slides around once per minute
if __name__ == "__main__":
    pixels = 27  # how many leds do you have.
    n = NeoPixel(pixels)
    n.setBrightness(1.0)
    while 1:
        (fractionOfMinute, dummy) = modf(time() / 60.0)
        for i in range(0, pixels - 1):
            p = i / float(pixels)  # 0.0..1.0 by position on string
            q = p + fractionOfMinute
            while q > 1:
                q = q - 1.0  # normalize for overflow
            (r, g, b) = colorsys.hsv_to_rgb(q, 1.0, 1.0)
            n.setPixelColor(i, toNeoPixelColor(r, g, b))
        n.show()
        sleep(0.2)
    n.clear()
    n.show()
    del n
    exit(0)