Example #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)
Example #2
0
 def set(self, out):
     pi.digital_write(self.pin, out)
Example #3
0
 def set(self, out):
     pi.digital_write(self.pin, out)