def main(): argc = len(sys.argv) if argc != 2: print "usage:%s pin" % sys.argv[0] return pin = int(sys.argv[1]) try: GPIO.setmode(GPIO.BOARD) GPIO.setup(pin, GPIO.IN) print "Get pin%d value %d" % (pin, GPIO.input(pin)) except Exception, e: print e
def MFRC522_Init(self): GPIO.output(self.NRSTPD, 1) self.MFRC522_Reset() self.Write_MFRC522(self.TModeReg, 0x8D) self.Write_MFRC522(self.TPrescalerReg, 0x3E) self.Write_MFRC522(self.TReloadRegL, 30) self.Write_MFRC522(self.TReloadRegH, 0) self.Write_MFRC522(self.TxAutoReg, 0x40) self.Write_MFRC522(self.ModeReg, 0x3D) self.AntennaOn()
def main(): try: led = 7 GPIO.setmode(GPIO.BOARD) GPIO.setup(led, GPIO.OUT) print "Light on" GPIO.output(led, GPIO.HIGH) time.sleep(1) print "Light off" GPIO.output(led, GPIO.LOW) except Exception, e: print e
def main(): argc = len(sys.argv) if argc != 2: print "usage:%s pin" % sys.argv[0] return pin = int(sys.argv[1]) try: GPIO.setmode(GPIO.BOARD) GPIO.setup(pin, GPIO.OUT) print "Set pin%d HIGH" % pin GPIO.output(pin, GPIO.HIGH) time.sleep(1) print "Set pin%d LOW" % pin GPIO.output(pin, GPIO.LOW) except Exception, e: print e
#!/usr/bin/env python import sys import time import Matrix.GPIO as GPIO def main(): argc = len(sys.argv) if argc != 2: print "usage:%s pin" % sys.argv[0] return pin = int(sys.argv[1]) try: GPIO.setmode(GPIO.BOARD) GPIO.setup(pin, GPIO.OUT) print "Set pin%d HIGH" % pin GPIO.output(pin, GPIO.HIGH) time.sleep(1) print "Set pin%d LOW" % pin GPIO.output(pin, GPIO.LOW) except Exception, e: print e finally: GPIO.cleanup() if __name__ == '__main__': main()
#!/usr/bin/env python import sys import time import Matrix.GPIO as GPIO def main(): argc = len(sys.argv) if argc != 2: print "usage:%s pin" % sys.argv[0] return pin = int(sys.argv[1]) try: GPIO.setmode(GPIO.BOARD) GPIO.setup(pin, GPIO.OUT) print "Set pin%d HIGH" % pin GPIO.output(pin, GPIO.HIGH) time.sleep(1) print "Set pin%d LOW" % pin GPIO.output(pin, GPIO.LOW) except Exception, e: print e finally: GPIO.cleanup() if __name__ == "__main__": main()
def __init__(self, dev='/dev/spidev0.0', spd=1000000): spi.openSPI(device=dev, speed=spd) GPIO.setmode(GPIO.BOARD) GPIO.setup(22, GPIO.OUT) GPIO.output(self.NRSTPD, 1) self.MFRC522_Init()
def end_read(signal, frame): global continue_reading print "Ctrl+C captured, ending read." continue_reading = False GPIO.cleanup()