import MCP3202, wiringpi, time, os # import library WiringPi-Python
from time import sleep # import library sleep

wiringpi.wiringPiSetup() # Must be called before using I/O Function
wiringpi.softPwmCreate(24, 0, 100) # Set PWM on pin 24, start value 0, max value 100

def translate(value, leftMin, leftMax, rightMin, rightMax):
	# Figure out how 'wide' each range is
	leftSpan = leftMax - leftMin
	rightSpan = rightMax - rightMin
	# Convert the left range into a 0-1 range (float)
	valueScaled = float(value - leftMin) / float(leftSpan)
	# Convert the 0-1 range into a value in the right range.
	return rightMin + (valueScaled * rightSpan)

try:	
	while True :					# endless loop
		os.system('clear')
		value1= MCP3202.readADC(1)		# range data 0 - vref (volt)
		map=translate(value1,0,4095,100,0)
		print "Ambient Light Monitoring"
		print "Curent Light : ",int(map),"%"
		print ""
		print "Press CTRL+C to exit"
		wiringpi.softPwmWrite(24,int(map))	# PWM pulse on pin 24
		sleep(0.02)                    		# delay for 20ms
		wiringpi.softPwmWrite(24,int(map))	# PWM pulse on pin 24
		sleep(0.02)                    		# delay for 20ms

except KeyboardInterrupt:
	wiringpi.softPwmWrite(24,0)			# PWM pulse on pin 24
	print "exit"

@@ -458,17 +458,19 @@
 into a 0
--
+ - 
 1 range 
@@ -549,17 +549,19 @@
 rt the 0
--
+ - 
 1 range 
@@ -591,17 +591,16 @@
 ht range
-.
 %0A%09return
@@ -642,17 +642,16 @@
 n)%0A%0Atry:
-%09
 %0A%09while 
@@ -658,15 +658,10 @@
 True
+:
  
-:%09%09%09%09%09
 # en
@@ -687,15 +687,15 @@
 tem(
-'
+%22
 clear
-'
+%22
 )%0A%09%09
@@ -724,45 +724,17 @@
 C(1)
-%09%09# range data 0 - vref (volt)
 %0A%09%09map
-=
+ = 
 tran
@@ -750,19 +750,23 @@
 ue1,
+ 
 0,
+ 
 4095,
+ 
 100,
+ 
 0)%0A%09
@@ -771,17 +771,17 @@
 %0A%09%09print
- 
+(
 %22Ambient
@@ -798,24 +798,25 @@
 itoring%22
+)
 %0A%09%09print
  %22Curent
@@ -807,17 +807,17 @@
 %0A%09%09print
- 
+(
 %22Curent 
@@ -826,16 +826,17 @@
 ght : %22,
+ 
 int(map)
@@ -840,19 +840,21 @@
 ap),
+ 
 %22%25%22
+)
 %0A%09%09print
  %22%22%0A
@@ -853,19 +853,20 @@
 rint
- 
+(
 %22%22
+)
 %0A%09%09print
  %22Pr
@@ -861,17 +861,17 @@
 %0A%09%09print
- 
+(
 %22Press C
@@ -884,16 +884,17 @@
 to exit%22
+)
 %0A%09%09wirin
@@ -905,32 +905,33 @@
 softPwmWrite(24,
+ 
 int(map))%09# PWM 
@@ -915,33 +915,33 @@
 te(24, int(map))
-%09
+ 
 # PWM pulse on p
@@ -960,37 +960,16 @@
 p(0.02) 
-                   %09%09
 # delay 
@@ -1004,16 +1004,17 @@
 rite(24,
+ 
 int(map)
@@ -1014,17 +1014,17 @@
 nt(map))
-%09
+ 
 # PWM pu
@@ -1055,29 +1055,8 @@
 02) 
-                   %09%09
 # de
@@ -1125,13 +1125,12 @@
 (24,
+ 
 0)
-%09%09%09
+ 
 # PW
@@ -1157,12 +1157,13 @@
 rint
- 
+(
 %22exit%22
+)
 %0A

Update 05_Ambient_Light_Monitoring.py