Пример #1
0
def connectPetduino():
	global pet_connected, pet
 	try:
		pet = Petduino(pet_port, pet_baud_rate)

		# Hookup event handlers
		pet.onState(onState)
		pet.onLed(onLed)
		pet.onTemperature(onTemperature)
		pet.onLightLevel(onLightLevel)
		pet.onBtn1(onBtn1)
		pet.onBtn2(onBtn2)	

		# Flag initialized
		print "Connected to Petduino on port:", pet_port
		pet_connected = True

	except Exception, e:
		print "Unable to connect to Petduino, retrying..."
		time.sleep(5)
		connectPetduino()
Пример #2
0
def connectPetduino():
    global pet_connected, pet
    try:
        pet = Petduino(pet_port, pet_baud_rate)

        # Hookup event handlers
        pet.onState(onState)
        pet.onLed(onLed)
        pet.onTemperature(onTemperature)
        pet.onLightLevel(onLightLevel)
        pet.onBtn1(onBtn1)
        pet.onBtn2(onBtn2)

        # Flag initialized
        print "Connected to Petduino on port:", pet_port
        pet_connected = True

    except Exception, e:
        print "Unable to connect to Petduino, retrying..."
        time.sleep(5)
        connectPetduino()
Пример #3
0
    if val:
        pet.getLightLevel()

def onTemperature(val):
    print "Petduino Temperature: ", val

def onLightLevel(val):
    print "Petduino Light Level: ", val

# Declare min process
if __name__ == '__main__':

    # Open connection to petduino
    pet =  Petduino(pet_port, pet_baud_rate)

    # Hookup event handlers
    pet.onBtn1(onBtn1)
    pet.onBtn2(onBtn2)
    pet.onTemperature(onTemperature)
    pet.onLightLevel(onLightLevel)

    try:
        print 'Press Ctrl+C to exit...'
        while True:
            # Do stuff
            time.sleep(0)

    except KeyboardInterrupt:
        # Stop procesing
        print 'Exiting...'
        pet.close()