def get_temperature_of_pi(): sense = SenseHat() sense.clear() data = get_all_data(sense) response = app.response_class(response=json.dumps(data), status=200, mimetype='application/json') return response
def move_left(self, sense): self.arduino.digitalWrite(self.Motor1A, self.arduino.LOW) self.arduino.digitalWrite(self.Motor2A, self.arduino.LOW) self.arduino.digitalWrite(self.Motor1B, self.arduino.LOW) self.arduino.digitalWrite(self.Motor2B, self.arduino.LOW) count = 0 while True: gevent.sleep(0.01) self.arduino.digitalWrite(self.Motor1A, self.arduino.HIGH) self.arduino.digitalWrite(self.Motor1B, self.arduino.LOW) self.arduino.digitalWrite(self.Motor2A, self.arduino.LOW) self.arduino.digitalWrite(self.Motor2B, self.arduino.HIGH) try: raw_data = get_all_data(sense) distance = self.startGetDistance() raw_data['distance'] = distance yield 'data: %s\n\n' % json.dumps(raw_data) except: yield 'data: there was an error!\n\n' count += 1
def move_forwards(self, sense): self.arduino.digitalWrite(self.Motor1A, self.arduino.LOW) self.arduino.digitalWrite(self.Motor2A, self.arduino.LOW) self.arduino.digitalWrite(self.Motor1B, self.arduino.LOW) self.arduino.digitalWrite(self.Motor2B, self.arduino.LOW) forwardsarrow.forwards() count = 0 while True: gevent.sleep(0.01) self.arduino.digitalWrite(self.Motor1A, self.arduino.HIGH) self.arduino.digitalWrite(self.Motor1B, self.arduino.LOW) self.arduino.digitalWrite(self.Motor2A, self.arduino.HIGH) self.arduino.digitalWrite(self.Motor2B, self.arduino.LOW) # distance test when moving forwards try: distance = self.startGetDistance() print('distance retrieved successfully') raw_data = get_all_data(sense) raw_data['distance'] = distance yield 'data: %s\n\n' % json.dumps(raw_data) except: yield 'data: there was an error!\n\n' count += 1