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()
def onBtn2(val): print "Petduino Btn2: ", val 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
from pypetduino import Petduino # Petduino settings pet_port = "/dev/ttyUSB0" pet_baud_rate = 9600 # Declare event handlers def onLed(val): print "Petduino Led: ", val # Declare min process if __name__ == '__main__': # Open connection to petduino pet = Petduino(pet_port, pet_baud_rate) # Hookup event handlers pet.onLed(onLed) try: print 'Press Ctrl+C to exit...' while True: # Do stuff pet.toggleLed() time.sleep(1) pet.getTemperature() time.sleep(1) except KeyboardInterrupt: # Stop procesing