Ejemplo n.º 1
0
    def update(self):
        #print "updating sonar"
        pi.digital_write(self.trig, 1)
        t.sleep(0.00001)
        pi.digital_write(self.trig, 0)

        start = t.time()
        test = start

        while pi.digital_read(self.echo) == 0:
            start = t.time()
            if test + .15 > t.time():
                end = -1
                print "failure"
                self.value = -1
                return
        
        end = start

        while pi.digital_read(self.echo) == 1:
            end = t.time()
            if end > start + .15:
                end = -1
                print "failure to get distance"
                self.value = -1
                return
            #t.sleep(.0001)

        timing = end - start
        self.value = (timing*340.29)
        print "done"

        pi.digital_write(self.trig, 0)
Ejemplo n.º 2
0
 def update(self):
     self.value = pi.digital_read(self.pin)
Ejemplo n.º 3
0
 def update(self):
     self.value = pi.digital_read(self.pin)