User Manual

74
Code Explanation
g_count = 0 # a global variable used to store the pulse count
def count(ev=None): Define a function to be run when an interrupt happens
global g_count # this function will change the value of the global variable g_count,
thus here we add global before it.
g_count += 1
GPIO.add_event_detect(SigPin, GPIO.RISING, callback=count) # set an interrupt here and
the interrupt signal is a rising edge for Pin Sig. It will run the function count()
accordingly
while True: # wait for the interrupt
print 'g_count = %d' % g_count # print the information
time.sleep(0.001)
SunFounder