def main(): # identify global variables that we will access in this function global leds, sb # create an instance of LEDStrip object - pass number of pixels and link to spi connection leds = ledstrip.LEDStrip(pixels=pixels, spi=spidev) # set spacesb name and create spacesb object sbName = ("Data Bar " + str(random.randint(0, 2000))) sb = spacebrew.SpaceBrew(sbName, server=args.server) # register all of the subscription channels sb.addSubscriber("light", "range") sb.addSubscriber("color_red", "range") sb.addSubscriber("color_green", "range") sb.addSubscriber("color_blue", "range") # associate a callback function to each subscription channel sb.subscribe("light", updateLight) sb.subscribe("color_red", updateRed) sb.subscribe("color_green", updateGreen) sb.subscribe("color_blue", updateBlue) # connect to spacesb sb.start() print "App is running and conected to Spacebrew name is ", sbName
def main(): # initialize spi and leds objects spidev = file("/dev/spidev0.0", "wb") # ref to spi connection to the led bar leds = ledstrip.LEDStrip(pixels=args.leds, spi=spidev) pixel_edge = 0 # current pixel whose state will be flipped turn_on = True # holds whether pixel will be switched on or off print "Let's start chasing" while (True): # update the pixel at the edge of the animation if turn_on == True: leds.setPixelColorRGB(pixel=pixel_edge, red=127, green=127, blue=127) else: leds.setPixelColorRGB(pixel=pixel_edge, red=0, green=0, blue=0) # update all leds leds.show() # move the chase forward pixel_edge = (pixel_edge + 1) % leds.numPixels() # when pixel goes back to start of strip then switch from on to off, or off to on if pixel_edge == 0: turn_on = not turn_on # delay for 20 milliseconds time.sleep(0.02)
def setUp(self): self.numberOfPixels = 32 self.spidevFile = "/dev/spidev0.0" self.spidev = open( self.spidevFile, "wb") # spidev is the file object of the SPI connection self.leds = ledstrip.LEDStrip( self.numberOfPixels, self.spidev) # Initialise the constructor.
def init(): global states global leds global timeout number_of_lights = 32 timeout = reactor.callLater(SHIFTTIME,shiftOne) states = deque(['unknown']*number_of_lights) spidev = file("/dev/spidev0.0", "wb") leds = ledstrip.LEDStrip(pixels=number_of_lights, spi=spidev)
def alarm_start(start_now): while True: now = time.time() if now >= start_now and now <= start_now + 1: # initialize spi and leds objects spidev = file("/dev/spidev0.0", "wb") # ref to spi connection to the led bar leds = ledstrip.LEDStrip(pixels=args.leds, spi=spidev) all_off(leds) logging.info('Starting alarm') alarm_on(leds, debug=False) time.sleep(600) logging.info('Stopping alarm') all_off(leds) break
def main(): # initialize spi and leds objects spidev = file("/dev/spidev0.0", "wb") # ref to spi connection to the led bar leds = ledstrip.LEDStrip(pixels=args.leds, spi=spidev) turn_off(leds) while True: ured, ugreen, ublue = raw_input( "Enter RGB values (x to exit): ").split() if ured == 'x': break for i in range(32): leds.setPixelColorRGB(pixel = i, red = int(ured), green = int(ugreen), blue = int(ublue)) leds.show() time.sleep(3) turn_off(leds)
def main(): # initialize spi and leds objects spidev = file("/dev/spidev0.0", "wb") # ref to spi connection to the led bar leds = ledstrip.LEDStrip(pixels=args.leds, spi=spidev) pixel_edge = 0 # current pixel whose state will be flipped turn_on = True # holds whether pixel will be switched on or off print "Let's start chasing" while (True): for pixel_edge in range(0, leds.numPixels()): if turn_on == True: if pixel_edge == 14 or pixel_edge == 15: leds.setPixelColorRGB(pixel=pixel_edge, red=127, green=127, blue=127) else: leds.setPixelColorRGB(pixel=pixel_edge, red=0, green=0, blue=0) else: if pixel_edge == 27: leds.setPixelColorRGB(pixel=pixel_edge, red=127, green=127, blue=127) else: leds.setPixelColorRGB(pixel=pixel_edge, red=0, green=0, blue=0) leds.show() turn_on = not turn_on time.sleep(1)
def __init__(self, numLeds): spidev = file("/dev/spidev0.0", "wb") # ref to spi connection to the led bar self.leds = ledstrip.LEDStrip(pixels=numLeds, spi=spidev) self.numLeds = numLeds self.onLeds = [0] * numLeds