Skip to content

Instantly share code, notes, and snippets.

@navin-bhaskar
Created April 8, 2015 15:29
Show Gist options
  • Select an option

  • Save navin-bhaskar/fe40305ee9ba3cfa6ac0 to your computer and use it in GitHub Desktop.

Select an option

Save navin-bhaskar/fe40305ee9ba3cfa6ac0 to your computer and use it in GitHub Desktop.
ADC example on Intel Galileo/Edison
#!/usr/bin/python
import mraa
import time
PWM_PIN = 5
ADC_PIN = 0 # Analog in pin
ROT_MAX = 1024.0 # Max value as measured by ADC when pot is connected
# Set up the PWM
pwm = mraa.Pwm(PWM_PIN)
pwm.enable(True)
pwm.period_us(5000)
# Set up the ADC
adc = mraa.Aio(ADC_PIN)
while 1:
value = adc.read() # Read the ADC value
led_intensity = value/ROT_MAX # Determine the duty cycle based on ADC value
pwm.write(led_intensity)
time.sleep(0.5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment