def makehigh(): print("\n value_%d = %d\n" %(channel,GPIO.input(channel))) GPIO.output(PIN_NUM,False) print("\n value_%d = %d\n" %(PIN_NUM,GPIO.input(PIN_NUM)))
print("\nNPi.GPIO version:") print(GPIO.VERSION) time.sleep(1) while True: try: pin = int( input( 'Choose board pin number: \n( 3 - 24; excluded: 4, 6, 9, 14, 17, 20 )\n' )) mode = int( input('Choose pin state: \n( 0 - Low, 1 - High, 2 - Quit )\n')) print("\n\nChoosen %d (state %s)\n" % (mode, v_modes_str[mode])) GPIO.setup(pin, GPIO.OUT) GPIO.output(pin, mode) time.sleep(0.5) print("Pin state changed!\n") #GPIO.setup(pin, GPIO.IN, pull_up_down=GPIO.PUD_OFF) time.sleep(0.5) print("Now pin %d state is: %s\n" % (pin, v_modes_str[GPIO.input(pin)])) time.sleep(3) except ValueError: print("Not a number") continue except IndexError: if mode == 2: GPIO.cleanup() print("Bye :-(\n") break
#!/usr/bin/env python from __future__ import print_function import NPi.GPIO as GPIO import time from threading import Timer PIN_NUM = 12 channel = 7 GPIO.setmode(GPIO.BOARD) GPIO.setup(PIN_NUM,GPIO.OUT) GPIO.output(PIN_NUM,True) print("\n value_%d = %d\n" %(PIN_NUM,GPIO.input(PIN_NUM))) GPIO.setup(channel,GPIO.IN,GPIO.PUD_DOWN) print("\n value_%d = %d\n" %(channel,GPIO.input(channel))) def makehigh(): print("\n value_%d = %d\n" %(channel,GPIO.input(channel))) GPIO.output(PIN_NUM,False) print("\n value_%d = %d\n" %(PIN_NUM,GPIO.input(PIN_NUM))) GPIO.wait_for_edge(channel, GPIO.RISING) t = Timer(1,makehigh) t.start()