Advertisement
Guest User

Untitled

a guest
Dec 7th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.66 KB | None | 0 0
  1. import math
  2. import sys
  3. import time
  4. from grove.adc import ADC
  5.  
  6.  
  7. class GroveLightSensor:
  8.  
  9.     def __init__(self, channel):
  10.         self.channel = channel
  11.         self.adc = ADC()
  12.  
  13.     @property
  14.     def light(self):
  15.         value = self.adc.read(self.channel)
  16.         return value
  17.  
  18. Grove = GroveLightSensor
  19.  
  20.  
  21. def main():
  22.     if len(sys.argv) < 2:
  23.         print('Usage: {} adc_channel'.format(sys.argv[0]))
  24.         sys.exit(1)
  25.  
  26.     sensor = GroveLightSensor(int(sys.argv[1]))
  27.  
  28.     print('Detecting light...')
  29.     while True:
  30.         print('Light value: {0}'.format(sensor.light))
  31.         time.sleep(1)
  32.  
  33. if __name__ == '__main__':
  34.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement