Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- import sys
- import time
- from grove.adc import ADC
- class GroveLightSensor:
- def __init__(self, channel):
- self.channel = channel
- self.adc = ADC()
- @property
- def light(self):
- value = self.adc.read(self.channel)
- return value
- Grove = GroveLightSensor
- def main():
- if len(sys.argv) < 2:
- print('Usage: {} adc_channel'.format(sys.argv[0]))
- sys.exit(1)
- sensor = GroveLightSensor(int(sys.argv[1]))
- print('Detecting light...')
- while True:
- print('Light value: {0}'.format(sensor.light))
- time.sleep(1)
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement