File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import RPi .GPIO as GPIO
2+ import time
3+ from ADCDevice import *
4+
5+ ledPin = 11
6+ adc = ADCDevice ()
7+
8+ def setup ():
9+ global adc
10+ if (adc .detectI2C (0x48 )):
11+ adc = PCF8591 ()
12+ elif (adc .detetctI2C (0X4b )):
13+ adc = ADS7830 ()
14+ else :
15+ print ("No correct 12C address found, \n "
16+ "please use command '12cdetect -y 1' to check the 12 C address! \n "
17+ "Program Exit. \n " ):
18+ exit (- 1 )
19+ global p
20+ GPIO .setmode (GPIO .BOARD )
21+ GPIO .setup (ledPin , GPOI . OUT )
22+ P = GPIO .PWM (ledPin , 1000 )
23+ p .start (0 )
24+
25+ def loop ():
26+ while True :
27+ value = adc .analogRead (0 )
28+ p .ChangeDutyCycle (value * 100 / 255 )
29+ voltage = value / 255.0 * 3.3
30+ print ('ADC Value : %d, Voltage : %2f' % (value , voltage ))
31+ time .sleep (0.03 )
32+
33+ def destroy ():
34+ adc .close ()
35+
36+ if __name__ == '__main__' :
37+ print ('Program is starting...' )
38+ try :
39+ setup ()
40+ loop ()
41+ except KeyboardInterrupt :
42+ destroy ()
You can’t perform that action at this time.
0 commit comments