document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. import time
  2.  
  3. from hw.commands import *
  4. from hw.usbdevice import *
  5.  
  6. def handle_packet(packet):
  7.     print Command.unpack(packet)
  8.  
  9. #use all defaults since that\'s the device I have
  10. dev = UsbDevice.find()
  11.  
  12. #start a thread to listen to messages from the device
  13. read_thread = UsbBackgroundRead(dev, handle_packet)
  14. read_thread.start()
  15.  
  16. #show firmware and setup device
  17. dev.send(GetFirmware().pack())
  18. dev.send(SetBit("TRISC", 6, 0).pack())
  19.  
  20. #blinking - send 0 to turn the led on, 1 for off
  21. for i in range(10):
  22.     dev.send(SetPortBit(Port.C, 6, 0).pack())
  23.     time.sleep(1)
  24.     dev.send(SetPortBit(Port.C, 6, 1).pack())
  25.     time.sleep(1)
  26.  
  27. read_thread.stop()
');