class WallClock(object): def __init__(self): # Create a NeoPixel object with 60 LEDs # and turn down the brightness self._strip=NeoPixel(60) self._strip.begin() self._strip.setBrightness(.25) self._strip.show() def tick(self): # Schedule the next tick to limit drift self._timer=Timer(1., self.tick) self._timer.start() # Get the current time now=datetime.now() second=now.second minute=now.minute hour=now.hour # Adjust 24hr time to 12hr time if hour>=12: hour-=12 # The hour is shown at every 5th LED hour*=5 # Clear the display self.clear() # Set the hour LED to blue self._strip.setPixelColor(hour, 0, 0, 255) # Set the minute LED to red unless the minute # hour LED are the same then alternate the colour # between red and blue every second if hour==minute and second%2: self._strip.setPixelColor(minute, 0, 0, 255) else: self._strip.setPixelColor(minute, 255, 0, 0) # Set the second LED to green self._strip.setPixelColor(second, 0, 255, 0) # Update the display self._strip.show() def clear(self): # Set every pixel off for i in range(60): self._strip.setPixelColor(i, 0, 0, 0) self._strip.show()
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
# ========== # # 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)
g = 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)
# WS2812-RPi # # ========== # # 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)