class GroveThumbJoystick: def __init__(self, channelX, channelY): self.channelX = channelX self.channelY = channelY self.adc = ADC() @property def value(self): return self.adc.read(self.channelX), self.adc.read(self.channelY)
class GroveLightSensor(object): 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(): from grove.helper import SlotHelper sh = SlotHelper(SlotHelper.ADC) pin = sh.argv2pin() sensor = GroveLightSensor(pin) print('Detecting light...') while True: print('Light value: {0}'.format(sensor.light)) up_lum = ('UPDATE capteur SET lumiere = %d WHERE id = 1' % sensor.light) cursor.execute() connexion.commit() time.sleep(1) if __name__ == '__main__': main()
class GroveLoudnessSensor: def __init__(self, channel): self.__channel = channel self.__adc = ADC() self.__sum = 0 self.__count = 0 self.__max = 0 @property def value(self): return self.__adc.read(self.__channel) @property def max(self): return self.__max @property def mean(self): return self.__sum / max(self.__count, 1) def record_value(self): self.__sum += self.value self.__count += 1 self.__max = max(self.__max, self.value) def reset_records(self): self.__sum = 0 self.__count = 0 self.__max = 0
class GroveLightSensor: def __init__(self, channel): self.__channel = channel self.__adc = ADC() self.__sum = 0 self.__count = 0 self.__max = 0 @property def light(self): value = self.__adc.read(self.__channel) return value @property def max(self): return self.__max @property def mean(self): return self.__sum / max(self.__count, 1) def record_value(self): self.__sum += self.light self.__count += 1 self.__max = max(self.__max, self.light) def reset_records(self): self.__sum = 0 self.__count = 0 self.__max = 0
class Co2Sensor: def __init__(self): self.channel = 0 self.adc = ADC() @property def value(self): return self.adc.read(self.channel)
class Sound(object): def __init__(self, pin): self.pin = pin self.adc = ADC() def read(self): value = self.adc.read(self.pin) return value
class GroveLoudnessSensor: def __init__(self, channel): self.channel = channel self.adc = ADC() @property def value(self): return self.adc.read(self.channel)
class GroveRoundForceSensor(ADC): def __init__(self, channel): self.channel = channel self.adc = ADC() @property def value(self): return self.adc.read(self.channel)
class GasSensorMQ2: def __init__(self, channel): self.channel = channel self.adc = ADC() @property def value(self): return self.adc.read(self.channel)
class LightSensor(): def __init__(self): self.channel = 2 self.adc = ADC() @property def brightness(self): return self.adc.read(self.channel)
class GroveFlex(ADC): def __init__(self, channel): self.channel = channel self.adc = ADC() @property def value(self): return self.adc.read(self.channel)
class GroveSlidePotentiometer(ADC): def __init__(self, channel): self.channel = channel self.adc = ADC() @property def value(self): return self.adc.read(self.channel)
class GroveGasSensorMQ2: def __init__(self, channel): self.channel = channel self.adc = ADC() @property def MQ2(self): value = self.adc.read(self.channel) return value
class GroveEMGdetector: def __init__(self, channel): self.channel = channel self.adc = ADC() @property def EMG(self): value = self.adc.read(self.channel) return value
class GSR(object): def __init__(self, pin): #Analog Port self.pin = pin self.adc = ADC() def read(self): value = self.adc.read(self.pin) return value
class GroveLightSensor: def __init__(self, channel): self.channel = channel self.adc = ADC() @property def light(self): value = self.adc.read(self.channel) return value
class GroveMoistureSensor: def __init__(self, channel): self.channel = channel self.adc = ADC() @property def moisture(self): value = self.adc.read(self.channel) return value
class GroveLightSensor: def __init__(self): self.channel = int(os.environ.get("analogue_channel_light")) self.adc = ADC() @property def light(self): value = self.adc.read(self.channel) return value
class GroveThumbJoystick(object): ''' Grove Thumb Joystick class Args: channel(int): number of analog pin/channel the sensor connected. ''' def __init__(self, channel): self.channelX = channel self.channelY = channel + 1 self.adc = ADC() @property def value(self): ''' Get the water strength value Returns: (pair): x-ratio, y-ratio, all are 0(0.0%) - 1000(100.0%) ''' return self.adc.read(self.channelX), self.adc.read(self.channelY)
class VibrationSensor(object): def __init__(self, channel): self.channel = channel self.adc = ADC() @property def vibration(self): ''' Get the strength value Returns: (int): ratio, 0(0.0%) - 1000(100.0%) ''' value = self.adc.read(self.channel) return value
class GroveWaterSensor: ''' Grove Water Sensor class Args: pin(int): number of analog pin/channel the sensor connected. ''' def __init__(self, channel): self.channel = channel self.adc = ADC() @property def value(self): ''' Get the water strength value Returns: (int): ratio, 0(0.0%) - 1000(100.0%) ''' return self.adc.read(self.channel)
class TemperTypedNTC(Temper): B = 4275. R0 = 100000. def __init__(self, channel): self.channel = channel self.adc = ADC() self._resolution = 1.5 # Celsius @property def temperature(self): value = self.adc.read(self.channel) if value <= 0 or value >= 1000: return float('nan') r = 1000. / value - 1. r = self.R0 * r return 1. / (math.log10(r / self.R0) / self.B + 1 / 298.15) - 273.15
class GroveLightSensor(object): ''' Grove Light Sensor class Args: pin(int): number of analog pin/channel the sensor connected. ''' def __init__(self, channel): self.channel = channel self.adc = ADC() @property def light(self): ''' Get the light strength value, maximum value is 100.0% Returns: (int): ratio, 0(0.0%) - 1000(100.0%) ''' value = self.adc.read(self.channel) return value
class GroveAirQualitySensor(object): ''' Grove Air Quality Sensor class Args: pin(int): number of analog pin/channel the sensor connected. ''' def __init__(self, channel): self.channel = channel self.adc = ADC() @property def value(self): ''' Get the air quality strength value, badest value is 100.0%. Returns: (int): ratio, 0(0.0%) - 1000(100.0%) ''' return self.adc.read(self.channel)
class GroveRotaryAngleSensor(ADC): ''' Grove Rotary Angle Sensor class Args: pin(int): number of analog pin/channel the sensor connected. ''' def __init__(self, channel): self.channel = channel self.adc = ADC() @property def value(self): ''' Get the rotary angle value, max angle is 100.0% Returns: (int): ratio, 0(0.0%) - 1000(100.0%) ''' return self.adc.read(self.channel)
class GroveRoundForceSensor(ADC): ''' Class for Grove - Round Force Sensor Args: pin(int): number of analog pin/channel the sensor connected. ''' def __init__(self, channel): self.channel = channel self.adc = ADC() @property def value(self): ''' Get the force strength value, the strengest value is 100.0%. Returns: (int): ratio, 0(0.0%) - 1000(100.0%) ''' return self.adc.read(self.channel)
class GroveSlidePotentiometer(ADC): ''' Grove Slide Poteniometer Sensor class Args: pin(int): number of analog pin/channel the sensor connected. ''' def __init__(self, channel): self.channel = channel self.adc = ADC() @property def value(self): ''' Get the position value, max position is 100.0%. Returns: (int): ratio, 0(0.0%) - 1000(100.0%) ''' return self.adc.read(self.channel)
adc = ADC() Offset = -2.2 print("name: {0:20}, version: {1:4}".format(adc.name, adc.version)) try: print('按下 Ctrl-C 可停止程式') lcd.clear() while True: lcd.cursor_pos = (0, 0) lcd.write_string("Date: {}".format(time.strftime("%Y/%m/%d"))) lcd.cursor_pos = (1, 0) lcd.write_string("Time: {}".format(time.strftime("%H:%M:%S"))) #voltage = adc.read_voltage(0)/1000 raw = adc.read_raw(0) voltage = adc.read_voltage(0) percent = adc.read(0) print("raw:{0:>6}, voltage:{1:>6}, percent(%):{2:>6} ".format( raw, voltage, percent)) # phValue = 7.0 + (voltage - 3.2) * (-5.5) # phValue= voltage*5.0/1024/6 # phValue=3.5*phValue+Offset # print(voltage, phValue) time.sleep(1) except KeyboardInterrupt: lcd.backlight_enabled = False print('關閉程式') finally: lcd.clear()