Skip to content

Commit e89d96e

Browse files
authored
Create softlight.py
1 parent f46b27f commit e89d96e

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

softlight.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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()

0 commit comments

Comments
 (0)