import MCP3202, wiringpi					# import library WiringPi2-Python
from time import sleep

wiringpi.wiringPiSetup()			# Must be called before using IO function
wiringpi.softPwmCreate(4,0,100)		# Create period signal = 20ms

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(0)	# range data 0 - vref (volt)
	map=translate(value1,0,4096,101,0)
 	print "Proximity Sensor"
	print "Curent Light : ",int(value1),int(map),"%"
    	print ""
	print "Press CTRL+C to exit"
	wiringpi.softPwmWrite(4,int(map))		# PWM pulse on pin 0
	sleep(1)                    		# delay for 20ms
	wiringpi.softPwmWrite(4,int(map))		# PWM pulse on pin 0
	sleep(1)                    		# delay for 20ms

except KeyboardInterrupt:
	print "exit"	

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

wiringpi.wiringPiSetup()		# Must be called before using IO function
wiringpi.softPwmCreate(2,0,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 1:					# endless loop
	os.system('clear')
	value1 = MCP3202.readADC(0)		# range data 0 - vref (volt)
	map = translate(value1,0,4095,0,100)
	position = translate (map,100,0,0,180)
 	print "Servo Position"
	print "Curent Position : ",int(position),"degree"
    	print ""
	print "Press CTRL+C to exit"
	wiringpi.softPwmWrite(2,int(map))	# PWM pulse on pin 9
	sleep(0.001)

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


Update 06_Potentiometer_Controlled_Servo.py