old_contents: #!/usr/bin/env python
  #
  # GrovePi Example for using the Grove Rotary Angle Sensor (Potentiometer) and the Grove LED to create LED sweep
  #
  # Modules:
  #	 http://www.seeedstudio.com/wiki/Grove_-_Rotary_Angle_Sensor
  #	 http://www.seeedstudio.com/wiki/Grove_-_LED_Socket_Kit
  # The GrovePi connects the Raspberry Pi and Grove sensors.  You can learn more about GrovePi here:  http://www.dexterindustries.com/GrovePi
  #
  # Have a question about this example?  Ask on the forums here:  http://www.dexterindustries.com/forum/?forum=grovepi
  #
  # LICENSE: 
  # These files have been made available online through a [Creative Commons Attribution-ShareAlike 3.0](http://creativecommons.org/licenses/by-sa/3.0/) license.
  
  import time
  import grovepi
  
  # Connect the Grove Rotary Angle Sensor to analog port A0
  # SIG,NC,VCC,GND
  potentiometer = 0
  
  # Connect the LED to digital port D5
  # SIG,NC,VCC,GND
  led = 5
  
  grovepi.pinMode(potentiometer,"INPUT")
  grovepi.pinMode(led,"OUTPUT")
  time.sleep(1)
  
  # Reference voltage of ADC is 5v
  adc_ref = 5
  
  # Vcc of the grove interface is normally 5v
  grove_vcc = 5
  
  # Full value of the rotary angle is 300 degrees, as per it's specs (0 to 300)
  full_angle = 300
  
  while True:
      try:
          # Read sensor value from potentiometer
          sensor_value = grovepi.analogRead(potentiometer)
  
          # Calculate voltage
          voltage = round((float)(sensor_value) * adc_ref / 1023, 2)
  
          # Calculate rotation in degrees (0 to 300)
          degrees = round((voltage * full_angle) / grove_vcc, 2)
  
          # Calculate LED brightess (0 to 255) from degrees (0 to 300)
          brightness = int(degrees / full_angle * 255)
  
          # Give PWM output to LED
          grovepi.analogWrite(led,brightness)
  
          print "sensor_value =", sensor_value, " voltage =", voltage, " degrees =", degrees, " brightness =", brightness
  
      except IOError:
          print "Error"
  
new_contents: #!/usr/bin/env python
  #
  # GrovePi Example for using the Grove Rotary Angle Sensor (Potentiometer) and the Grove LED to create LED sweep
  #
  # Modules:
  #	 http://www.seeedstudio.com/wiki/Grove_-_Rotary_Angle_Sensor
  #	 http://www.seeedstudio.com/wiki/Grove_-_LED_Socket_Kit
  # The GrovePi connects the Raspberry Pi and Grove sensors.  You can learn more about GrovePi here:  http://www.dexterindustries.com/GrovePi
  #
  # Have a question about this example?  Ask on the forums here:  http://www.dexterindustries.com/forum/?forum=grovepi
  #
  # LICENSE: 
  # These files have been made available online through a [Creative Commons Attribution-ShareAlike 3.0](http://creativecommons.org/licenses/by-sa/3.0/) license.
  
  import time
  import grovepi
  
  # Connect the Grove Rotary Angle Sensor to analog port A0
  # SIG,NC,VCC,GND
  potentiometer = 0
  
  # Connect the LED to digital port D5
  # SIG,NC,VCC,GND
  led = 5
  
  grovepi.pinMode(potentiometer,"INPUT")
  grovepi.pinMode(led,"OUTPUT")
  time.sleep(1)
  
  # Reference voltage of ADC is 5v
  adc_ref = 5
  
  # Vcc of the grove interface is normally 5v
  grove_vcc = 5
  
  # Full value of the rotary angle is 300 degrees, as per it's specs (0 to 300)
  full_angle = 300
  
  while True:
      try:
          # Read sensor value from potentiometer
          sensor_value = grovepi.analogRead(potentiometer)
  
          # Calculate voltage
          voltage = round((float)(sensor_value) * adc_ref / 1023, 2)
  
          # Calculate rotation in degrees (0 to 300)
          degrees = round((voltage * full_angle) / grove_vcc, 2)
  
          # Calculate LED brightess (0 to 255) from degrees (0 to 300)
          brightness = int(degrees / full_angle * 255)
  
          # Give PWM output to LED
          grovepi.analogWrite(led,brightness)
  
          print "sensor_value =", sensor_value, " voltage =", voltage, " degrees =", degrees, " brightness =", brightness
      except KeyboardInterrupt:
          grovepi.analogWrite(led,0)
          break
      except IOError:
          print "Error"
  
subject: Update grove_rotary_angle_sensor.py