Professional Documents
Culture Documents
/usr/bin/env python
import RPi.GPIO as GPIO
import ADC0832
import time
'''
Example how to use the hall-sensor with digital and analog output
While the loop is printing the analog values, an interrupt-method
is waiting for changes on the digital pin. In case of any change
the message "change detected" is displayed.
Example output:
res0 = 138, res1 = 0
res0 = 133, res1 = 0
Change detected
res0 = 116, res1 = 0
Change detected
res0 = 132, res1 = 0
res0 = 138, res1 = 0
'''
GPIO.setwarnings(False)
# Setup pins
GPIO.setup(HALL,GPIO.IN, pull_up_down=GPIO.PUD_UP)
def init():
ADC0832.setup()
def loop():
while True:
res0 = ADC0832.getResult(0)
res1 = ADC0832.getResult(1)
print 'res0 = %d, res1 = %d' % (res0,res1)
time.sleep(0.2)
if __name__ == '__main__':
init()
try:
loop()
except KeyboardInterrupt:
ADC0832.destroy()