def read(self): current_reading = grovepi.digitalRead(self.pin) if self.last_flow_reading != current_reading: self.flow_counters['stop'] = 0 self.flow_counters['start'] += 1 self.last_flow_reading = current_reading if (self.flow_counters['start'] >= THRESHOLDS['start']): self.flowing = True else: self.flow_counters['stop'] += 1 if self.flowing: self.flow_count += 1 if self.flow_counters['stop'] > THRESHOLDS['stop'] and self.flow_count > 0: self.flow_counters['start'] = 0 self.flow_counters['stop'] = 0 self.flowing = False self.flow_count = 0 return current_reading
def read(self): current_reading = grovepi.digitalRead(self.pin) if self.last_flow_reading != current_reading: self.flow_counters['stop'] = 0 self.flow_counters['start'] += 1 self.last_flow_reading = current_reading if (self.flow_counters['start'] >= THRESHOLDS['start']): self.flowing = True else: self.flow_counters['stop'] += 1 if self.flowing: self.flow_count += 1 if self.flow_counters['stop'] > THRESHOLDS[ 'stop'] and self.flow_count > 0: self.flow_counters['start'] = 0 self.flow_counters['stop'] = 0 self.flowing = False self.flow_count = 0 return current_reading
def is_down(self): if (grovepi.digitalRead(self.pin) == 1): return True else: return False pass
def is_down(self): if (grovepi.digitalRead(self.pin)==1): return True else: return False pass
while True: #init if not initialized: setRGB(0, 50, 0) setText("Getting data..") initialized = True #Try to read the sensor measurements try: light_intensity = grovepi.analogRead(light_sensor) [temp, hum] = grovepi.dht(dht_sensor_port, dht_sensor_type) sound_level = grovepi.analogRead(sound_sensor) wind_dir_raw = grovepi.analogRead(rotary_sensor) switch = grovepi.digitalRead(button) distance = grovepi.ultrasonicRead(ultrasonic_ranger) if wind_dir_raw == 0: wind_direction = 0 else: wind_direction = wind_dir_raw * (360 / 1024.0) wind_direction = float("{0:.1f}".format(wind_direction)) #Save locally sensor_values[0] = light_intensity sensor_values[1] = temp sensor_values[2] = hum sensor_values[3] = sound_level sensor_values[4] = wind_direction