def do(self, action): print self._blinking_loop if self._blinking_loop is not None: try: self._blinking_loop.stop() except: pass if action is not None: for k, v in action.iteritems(): if k == 'state': grovepi.digitalWrite(self._pin, v) elif k == 'blink': self._blinking_period = float(v) self._blinking_loop = task.LoopingCall(self._blink) self._blinking_loop.start(self._blinking_period) print 'action done'
def _read(self): data = {} sensor_value = grovepi.analogRead(self._pin) data['gas_measurement'] = sensor_value gas_density = float(sensor_value) / 1024.0 data['gas_density'] = gas_density return data
def _read(self): data = {} sensor_value = grovepi.analogRead(self._pin) amplitude = float(sensor_value) / 1024.0 * _vcc / 800.0 * 2000000.0 effective = amplitude_current / 1.414 data['measurement'] = sensor_value data['amplitude'] = amplitude data['effective'] = effective return data
def _read(self): data = {} data['distance'] = grovepi.ultrasonicRead(self._pin) presence = data.get('distance') < 50 if presence == True: data['presence'] = 1 else: data['presence'] = 0 return data
def _read(self): data = {} data['vibrating'] = grovepi.analogRead(self._pin) return data
def _read(self): data = {} data['moisture'] = grovepi.analogRead(self._pin) return data
def _read(self): data = {} sensor_value = grovepi.analogRead(self._pin) data['light'] = sensor_value return data
def _read(self): data = {} sensor_value = grovepi.analogRead(self._pin) data['potentiometer'] = sensor_value return data
def _init_sensor(self): try: grovepi.pinMode(self._pin, "INPUT") except: pass
def do(self, action): if action is not None: for k, v in action.iteritems(): if k == 'level': grovepi.ledBar_setLevel(self._pin, v)
def _init_actuator(self): grovepi.ledBar_init(self._pin, 0) sleep(0.5) grovepi.ledBar_setLevel(self._pin, 5)
def do(self, action): if action is not None: for k, v in action.iteritems(): if k == 'state': grovepi.digitalWrite(self._pin, v)
def _init_actuator(self): grovepi.pinMode(self._pin, 'OUTPUT')
def _blink(self): grovepi.digitalWrite(self._pin, self._led_status) if self._led_status == 0: self._led_status = 1 else: self._led_status = 0
def _read(self): data = {} data['motion'] = grovepi.digitalRead(self._pin) return data
def _read(self): data = {} data['flame'] = grovepi.digitalRead(self._pin) return data
def _read(self): data = {} sensor_value = grovepi.analogRead(self._pin) data['sound_measurement'] = sensor_value return data
def _read(self): data = {} [temp, humidity] = grovepi.dht(self._pin, 1) data['temperature'] = temp data['humidity'] = humidity return data
def _init_actuator(self): grovepi.pinMode(self._pin, 'OUTPUT') self._blinking_loop = task.LoopingCall(self._blink) self._blinking_loop.start(0.5)