def device_method_callback(method_name, payload, user_context): global INTERVAL print("\nMethod callback called with:\nmethodName = %s\npayload = %s" % (method_name, payload)) device_method_return_value = DeviceMethodReturnValue() if method_name == "SetLED": try: #INTERVAL = int(payload) if (int(payload) == 1): grovepi.chainableRgbLed_test(pin, numleds, testColorWhite) time.sleep(1) elif (int(payload) == 0): grovepi.chainableRgbLed_test(pin, numleds, testColorBlack) time.sleep(1) # Build and send the acknowledgment. device_method_return_value.response = "{ \"Response\": \"Executed direct method %s\" }" % method_name device_method_return_value.status = 200 except ValueError: # Build and send an error response. device_method_return_value.response = "{ \"Response\": \"Invalid parameter\" }" device_method_return_value.status = 400 else: # Build and send an error response. device_method_return_value.response = "{ \"Response\": \"Direct method not defined: %s\" }" % method_name device_method_return_value.status = 404 return device_method_return_value
def led_random(): #print "Change LED Color" # test pattern 1 blue try: grovepi.chainableRgbLed_test(ledpin, numleds, random.randint(0,7)) # time.sleep(1) except: print "led_random failure"
def led_random(): #print "Change LED Color" # test pattern 1 blue try: grovepi.chainableRgbLed_test(ledpin, numleds, random.randint(0, 7)) # time.sleep(1) except: print("led_random failure")
def initalize_chained_led(): print("Test 1) Initialise") # init chain of leds grovepi.chainableRgbLed_init(ledpin, numleds) time.sleep(.5) grovepi.chainableRgbLed_test(ledpin, numleds, random.randint(0, 7)) time.sleep(.5)
def initalize_chained_led(): print("Test 1) Initialise") # init chain of leds grovepi.chainableRgbLed_init(ledpin, numleds) time.sleep(.5) grovepi.chainableRgbLed_test(ledpin, numleds, random.randint(0,7)) time.sleep(.5)
def change_light(self, isOn): """ Switch the light ON or OFF. """ try: import grovepi except ImportError: return if isOn: grovepi.chainableRgbLed_pattern(self.led_pin, 0, 0) self.led_is_on = True else: grovepi.chainableRgbLed_test(self.led_pin, self.nb_leds, 0) self.led_is_on = False
def listen_sending_status(self, s): DOOR = False #False = Close / True = Open BUTTONSTATE = False SENDING = True DOOR1 = False DOORRESET = False pin = 7 numleds = 4 grovepi.pinMode(pin, "OUTPUT") testColorBlack = 0 # 0b000 #000000 testColorRed = 4 # 0b100 #FF0000 while True: try: if CapteurService.stateDoor == 0: DOOR = False #door close else: DOOR = True #door open BUTTONSTATE = CapteurService.stateButton if (DOOR == True and BUTTONSTATE == True and SENDING == True): grovepi.chainableRgbLed_test(pin, numleds, testColorRed) print("Colis posee dans la boite a : " + str(datetime.datetime.now())) self.packDepositeInMBox = str(datetime.datetime.now()) SENDING = False if (SENDING == False and DOOR == False): DOOR1 = True if (DOOR1 == True and DOOR == True): SENDING = True grovepi.chainableRgbLed_test(pin, numleds, testColorBlack) print("Colis pris par le facteur a : " + str(datetime.datetime.now())) self.packTookOfMBox = str(datetime.datetime.now()) DOOR1 = False DOORRESET = False time.sleep(.1) except IOError as e: print "I/O error({0}): {1}".format(e.errno, e.strerror) time.sleep(0.5) return
def receive_message_callback(message, counter): global RECEIVED_COUNT global RECEIVE_CALLBACKS message_buffer = message.get_bytearray() size = len(message_buffer) print("Received Message [%d]:" % RECEIVED_COUNT) msg_data = message_buffer[:size].decode('utf-8') # 收到的信息 print("Recieved control order: %s" % msg_data) print(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))) if msg_data == "open": grovepi.chainableRgbLed_test(pin, numleds, testColorWhite) elif msg_data == "close": grovepi.chainableRgbLed_test(pin, numleds, testColorBlack) else: print("Do nothing!") RECEIVED_COUNT += 1 RECEIVE_CALLBACKS += 1 print(" Total calls received: %d" % RECEIVE_CALLBACKS) print(" Command: %s" % msg_data[7:-1]) return IoTHubMessageDispositionResult.ACCEPTED
grovepi.chainableRgbLed_pattern(pin, thisLedOnly, 0) time.sleep(.5) # change color to red grovepi.storeColor(255,0,0) time.sleep(.5) # set led 10 to red grovepi.chainableRgbLed_pattern(pin, thisLedOnly, 9) time.sleep(.5) # pause so you can see what happened time.sleep(2) # reset (all off) grovepi.chainableRgbLed_test(pin, numleds, testColorBlack) time.sleep(.5) print ("Test 2a) Test Patterns - black") # test pattern 0 - black (all off) grovepi.chainableRgbLed_test(pin, numleds, testColorBlack) time.sleep(1) print ("Test 2b) Test Patterns - blue") # test pattern 1 blue grovepi.chainableRgbLed_test(pin, numleds, testColorBlue) time.sleep(1)
grovepi.digitalWrite(feedbackLEDPort, 0) # Init Chainable RGB LED grovepi.chainableRgbLed_init(rgbLEDPort, num_of_leds) # Create threading object # radio_timer = MyThreading(5400, kill_mplayer) rgbled_timer = MyThreading(40, return_color, ()) # Init mplayer kill_mplayer() # start up blink startup_blink = [7,6,5,4,3,2,1,0,7] for i in startup_blink: grovepi.chainableRgbLed_test(rgbLEDPort, num_of_leds, i) time.sleep(.1) [new_val, encoder_val] = grovepi.encoderRead() if encoder_val == 0: color_rgb = [0, 0, 0] else: color_rgb = [255, 0, 0] grovepi.storeColor(color_rgb[0], color_rgb[1], color_rgb[2]) grovepi.chainableRgbLed_pattern(rgbLEDPort, thisLedOnly, 0) # recieve SIGTERM signal.signal(signal.SIGTERM, signal_term_handler)
def chained_led(): try: # set led 1 to green grovepi.chainableRgbLed_pattern(pin, thisLedOnly, 0) time.sleep(.5) # change color to red grovepi.storeColor(255, 0, 0) time.sleep(.5) # reset (all off) grovepi.chainableRgbLed_test(pin, numleds, testColorBlack) time.sleep(.5) print("Test 2b) Test Patterns - blue") # test pattern 1 blue grovepi.chainableRgbLed_test(pin, numleds, testColorBlue) time.sleep(1) print("Test 2c) Test Patterns - green") # test pattern 2 green grovepi.chainableRgbLed_test(pin, numleds, testColorGreen) time.sleep(1) print("Test 2d) Test Patterns - cyan") # test pattern 3 cyan grovepi.chainableRgbLed_test(pin, numleds, testColorCyan) time.sleep(1) print("Test 2e) Test Patterns - red") # test pattern 4 red grovepi.chainableRgbLed_test(pin, numleds, testColorRed) time.sleep(1) print("Test 2f) Test Patterns - magenta") # test pattern 5 magenta grovepi.chainableRgbLed_test(pin, numleds, testColorMagenta) time.sleep(1) print("Test 2g) Test Patterns - yellow") # test pattern 6 yellow grovepi.chainableRgbLed_test(pin, numleds, testColorYellow) time.sleep(1) print("Test 2h) Test Patterns - white") # test pattern 7 white grovepi.chainableRgbLed_test(pin, numleds, testColorWhite) time.sleep(1) # pause so you can see what happened time.sleep(2) # reset (all off) grovepi.chainableRgbLed_test(pin, numleds, testColorBlack) time.sleep(.5) print("Test 3a) Set using pattern - this led only") # change color to red grovepi.storeColor(255, 0, 0) time.sleep(.5) # set led 3 to red grovepi.chainableRgbLed_pattern(pin, thisLedOnly, 2) time.sleep(.5) # pause so you can see what happened time.sleep(2) # reset (all off) grovepi.chainableRgbLed_test(pin, numleds, testColorBlack) time.sleep(.5) print("Test 3b) Set using pattern - all leds except this") # change color to blue grovepi.storeColor(0, 0, 255) time.sleep(.5) # set all leds except for 3 to blue grovepi.chainableRgbLed_pattern(pin, allLedsExceptThis, 3) time.sleep(.5) # pause so you can see what happened time.sleep(2) # reset (all off) grovepi.chainableRgbLed_test(pin, numleds, testColorBlack) time.sleep(.5) print("Test 3c) Set using pattern - this led and inwards") # change color to green grovepi.storeColor(0, 255, 0) time.sleep(.5) # set leds 1-3 to green grovepi.chainableRgbLed_pattern(pin, thisLedAndInwards, 2) time.sleep(.5) # pause so you can see what happened time.sleep(2) # reset (all off) grovepi.chainableRgbLed_test(pin, numleds, testColorBlack) time.sleep(.5) print("Test 3d) Set using pattern - this led and outwards") # change color to green grovepi.storeColor(0, 255, 0) time.sleep(.5) # set leds 7-10 to green grovepi.chainableRgbLed_pattern(pin, thisLedAndOutwards, 6) time.sleep(.5) # pause so you can see what happened time.sleep(2) # reset (all off) grovepi.chainableRgbLed_test(pin, numleds, testColorBlack) time.sleep(.5) print("Test 4a) Set using modulo - all leds") # change color to black (fully off) grovepi.storeColor(0, 0, 0) time.sleep(.5) # set all leds black # offset 0 means start at first led # divisor 1 means every led grovepi.chainableRgbLed_modulo(pin, 0, 1) time.sleep(.5) # change color to white (fully on) grovepi.storeColor(255, 255, 255) time.sleep(.5) # set all leds white grovepi.chainableRgbLed_modulo(pin, 0, 1) time.sleep(.5) # pause so you can see what happened time.sleep(2) # reset (all off) grovepi.chainableRgbLed_test(pin, numleds, testColorBlack) time.sleep(.5) print("Test 4b) Set using modulo - every 2") # change color to red grovepi.storeColor(255, 0, 0) time.sleep(.5) # set every 2nd led to red grovepi.chainableRgbLed_modulo(pin, 0, 2) time.sleep(.5) # pause so you can see what happened time.sleep(2) print("Test 4c) Set using modulo - every 2, offset 1") # change color to green grovepi.storeColor(0, 255, 0) time.sleep(.5) # set every 2nd led to green, offset 1 grovepi.chainableRgbLed_modulo(pin, 1, 2) time.sleep(.5) # pause so you can see what happened time.sleep(2) # reset (all off) grovepi.chainableRgbLed_test(pin, numleds, testColorBlack) time.sleep(.5) print("Test 4d) Set using modulo - every 3, offset 0") # change color to red grovepi.storeColor(255, 0, 0) time.sleep(.5) # set every 3nd led to red grovepi.chainableRgbLed_modulo(pin, 0, 3) time.sleep(.5) # change color to green grovepi.storeColor(0, 255, 0) time.sleep(.5) # set every 3nd led to green, offset 1 grovepi.chainableRgbLed_modulo(pin, 1, 3) time.sleep(.5) # change color to blue grovepi.storeColor(0, 0, 255) time.sleep(.5) # set every 3nd led to blue, offset 2 grovepi.chainableRgbLed_modulo(pin, 2, 3) time.sleep(.5) # pause so you can see what happened time.sleep(2) # reset (all off) grovepi.chainableRgbLed_test(pin, numleds, testColorBlack) time.sleep(.5) print("Test 4e) Set using modulo - every 3, offset 1") # change color to yellow grovepi.storeColor(255, 255, 0) time.sleep(.5) # set every 4nd led to yellow grovepi.chainableRgbLed_modulo(pin, 1, 3) time.sleep(.5) # pause so you can see what happened time.sleep(2) print("Test 4f) Set using modulo - every 3, offset 2") # change color to magenta grovepi.storeColor(255, 0, 255) time.sleep(.5) # set every 4nd led to magenta grovepi.chainableRgbLed_modulo(pin, 2, 3) time.sleep(.5) # pause so you can see what happened time.sleep(2) # reset (all off) grovepi.chainableRgbLed_test(pin, numleds, testColorBlack) time.sleep(.5) print("Test 5a) Set level 6") # change color to green grovepi.storeColor(0, 255, 0) time.sleep(.5) # set leds 1-6 to green grovepi.write_i2c_block(0x04, [95, pin, 6, 0]) time.sleep(.5) # pause so you can see what happened time.sleep(2) # reset (all off) grovepi.chainableRgbLed_test(pin, numleds, testColorBlack) time.sleep(.5) print("Test 5b) Set level 7 - reverse") # change color to red grovepi.storeColor(255, 0, 0) time.sleep(.5) # set leds 4-10 to red grovepi.write_i2c_block(0x04, [95, pin, 7, 1]) time.sleep(.5) except KeyboardInterrupt: # reset (all off) grovepi.chainableRgbLed_test(pin, numleds, testColorBlack) except IOError: print("Error")
def chained_led(): try: # set led 1 to green grovepi.chainableRgbLed_pattern(pin, thisLedOnly, 0) time.sleep(.5) # change color to red grovepi.storeColor(255,0,0) time.sleep(.5) # reset (all off) grovepi.chainableRgbLed_test(pin, numleds, testColorBlack) time.sleep(.5) print ("Test 2b) Test Patterns - blue") # test pattern 1 blue grovepi.chainableRgbLed_test(pin, numleds, testColorBlue) time.sleep(1) print ("Test 2c) Test Patterns - green") # test pattern 2 green grovepi.chainableRgbLed_test(pin, numleds, testColorGreen) time.sleep(1) print ("Test 2d) Test Patterns - cyan") # test pattern 3 cyan grovepi.chainableRgbLed_test(pin, numleds, testColorCyan) time.sleep(1) print ("Test 2e) Test Patterns - red") # test pattern 4 red grovepi.chainableRgbLed_test(pin, numleds, testColorRed) time.sleep(1) print ("Test 2f) Test Patterns - magenta") # test pattern 5 magenta grovepi.chainableRgbLed_test(pin, numleds, testColorMagenta) time.sleep(1) print ("Test 2g) Test Patterns - yellow") # test pattern 6 yellow grovepi.chainableRgbLed_test(pin, numleds, testColorYellow) time.sleep(1) print ("Test 2h) Test Patterns - white") # test pattern 7 white grovepi.chainableRgbLed_test(pin, numleds, testColorWhite) time.sleep(1) # pause so you can see what happened time.sleep(2) # reset (all off) grovepi.chainableRgbLed_test(pin, numleds, testColorBlack) time.sleep(.5) print ("Test 3a) Set using pattern - this led only") # change color to red grovepi.storeColor(255,0,0) time.sleep(.5) # set led 3 to red grovepi.chainableRgbLed_pattern(pin, thisLedOnly, 2) time.sleep(.5) # pause so you can see what happened time.sleep(2) # reset (all off) grovepi.chainableRgbLed_test(pin, numleds, testColorBlack) time.sleep(.5) print ("Test 3b) Set using pattern - all leds except this") # change color to blue grovepi.storeColor(0,0,255) time.sleep(.5) # set all leds except for 3 to blue grovepi.chainableRgbLed_pattern(pin, allLedsExceptThis, 3) time.sleep(.5) # pause so you can see what happened time.sleep(2) # reset (all off) grovepi.chainableRgbLed_test(pin, numleds, testColorBlack) time.sleep(.5) print ("Test 3c) Set using pattern - this led and inwards") # change color to green grovepi.storeColor(0,255,0) time.sleep(.5) # set leds 1-3 to green grovepi.chainableRgbLed_pattern(pin, thisLedAndInwards, 2) time.sleep(.5) # pause so you can see what happened time.sleep(2) # reset (all off) grovepi.chainableRgbLed_test(pin, numleds, testColorBlack) time.sleep(.5) print ("Test 3d) Set using pattern - this led and outwards") # change color to green grovepi.storeColor(0,255,0) time.sleep(.5) # set leds 7-10 to green grovepi.chainableRgbLed_pattern(pin, thisLedAndOutwards, 6) time.sleep(.5) # pause so you can see what happened time.sleep(2) # reset (all off) grovepi.chainableRgbLed_test(pin, numleds, testColorBlack) time.sleep(.5) print ("Test 4a) Set using modulo - all leds") # change color to black (fully off) grovepi.storeColor(0,0,0) time.sleep(.5) # set all leds black # offset 0 means start at first led # divisor 1 means every led grovepi.chainableRgbLed_modulo(pin, 0, 1) time.sleep(.5) # change color to white (fully on) grovepi.storeColor(255,255,255) time.sleep(.5) # set all leds white grovepi.chainableRgbLed_modulo(pin, 0, 1) time.sleep(.5) # pause so you can see what happened time.sleep(2) # reset (all off) grovepi.chainableRgbLed_test(pin, numleds, testColorBlack) time.sleep(.5) print ("Test 4b) Set using modulo - every 2") # change color to red grovepi.storeColor(255,0,0) time.sleep(.5) # set every 2nd led to red grovepi.chainableRgbLed_modulo(pin, 0, 2) time.sleep(.5) # pause so you can see what happened time.sleep(2) print ("Test 4c) Set using modulo - every 2, offset 1") # change color to green grovepi.storeColor(0,255,0) time.sleep(.5) # set every 2nd led to green, offset 1 grovepi.chainableRgbLed_modulo(pin, 1, 2) time.sleep(.5) # pause so you can see what happened time.sleep(2) # reset (all off) grovepi.chainableRgbLed_test(pin, numleds, testColorBlack) time.sleep(.5) print ("Test 4d) Set using modulo - every 3, offset 0") # change color to red grovepi.storeColor(255,0,0) time.sleep(.5) # set every 3nd led to red grovepi.chainableRgbLed_modulo(pin, 0, 3) time.sleep(.5) # change color to green grovepi.storeColor(0,255,0) time.sleep(.5) # set every 3nd led to green, offset 1 grovepi.chainableRgbLed_modulo(pin, 1, 3) time.sleep(.5) # change color to blue grovepi.storeColor(0,0,255) time.sleep(.5) # set every 3nd led to blue, offset 2 grovepi.chainableRgbLed_modulo(pin, 2, 3) time.sleep(.5) # pause so you can see what happened time.sleep(2) # reset (all off) grovepi.chainableRgbLed_test(pin, numleds, testColorBlack) time.sleep(.5) print ("Test 4e) Set using modulo - every 3, offset 1") # change color to yellow grovepi.storeColor(255,255,0) time.sleep(.5) # set every 4nd led to yellow grovepi.chainableRgbLed_modulo(pin, 1, 3) time.sleep(.5) # pause so you can see what happened time.sleep(2) print ("Test 4f) Set using modulo - every 3, offset 2") # change color to magenta grovepi.storeColor(255,0,255) time.sleep(.5) # set every 4nd led to magenta grovepi.chainableRgbLed_modulo(pin, 2, 3) time.sleep(.5) # pause so you can see what happened time.sleep(2) # reset (all off) grovepi.chainableRgbLed_test(pin, numleds, testColorBlack) time.sleep(.5) print ("Test 5a) Set level 6") # change color to green grovepi.storeColor(0,255,0) time.sleep(.5) # set leds 1-6 to green grovepi.write_i2c_block(0x04,[95,pin,6,0]) time.sleep(.5) # pause so you can see what happened time.sleep(2) # reset (all off) grovepi.chainableRgbLed_test(pin, numleds, testColorBlack) time.sleep(.5) print ("Test 5b) Set level 7 - reverse") # change color to red grovepi.storeColor(255,0,0) time.sleep(.5) # set leds 4-10 to red grovepi.write_i2c_block(0x04,[95,pin,7,1]) time.sleep(.5) except KeyboardInterrupt: # reset (all off) grovepi.chainableRgbLed_test(pin, numleds, testColorBlack) except IOError: print ("Error")
turn_on_led(0,0,255,0) time.sleep(sleep_time) # turn on led at 1 print("2") turn_off_led(0) turn_on_led(1,0,255,0) time.sleep(sleep_time) # turn on led at 2 print("3") turn_off_led(1) turn_on_led(2,0,255,0) time.sleep(sleep_time) # turn on led at 3 print("4") turn_off_led(2) turn_on_led(3,0,255,0) time.sleep(sleep_time) # turn off all print("Off") grovepi.chainableRgbLed_test(pin, numleds, testColorBlack) time.sleep(sleep_time) except KeyboardInterrupt: # reset (all off) grovepi.chainableRgbLed_test(pin, numleds, testColorBlack) except IOError: print ("Error")
self.services = [ self.receptionservice, self.envoiservice, self.capteurservice ] self.receptionservice.startListening() self.envoiservice.startListening() self.capteurservice.startListening() self.icons = [ DeviceIcon('image/png', 32, 32, 24, 'http://172.25.3.103:52323/MediaRenderer_32x32.png') ] if __name__ == '__main__': #Logr.configure(logging.DEBUG) grovepi.chainableRgbLed_test(pin, numleds, 0) grovepi.chainableRgbLed_test(pin, numleds, 2) time.sleep(1) grovepi.chainableRgbLed_test(pin, numleds, 0) time.sleep(1) grovepi.chainableRgbLed_test(pin, numleds, 2) time.sleep(1) grovepi.chainableRgbLed_test(pin, numleds, 0) device = SmartilDevice() upnp = UPnP(device) ssdp = SSDP(device) upnp.listen() ssdp.listen() print("Smartil is ready !") reactor.run()
def setColorLed(self, color): print(color) grovepi.chainableRgbLed_test(pin, numleds, int(color))