Created
April 8, 2015 15:29
-
-
Save navin-bhaskar/fe40305ee9ba3cfa6ac0 to your computer and use it in GitHub Desktop.
ADC example on Intel Galileo/Edison
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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