Beispiel #1
0
def measure(trigger, echo):
    bbio.digitalWrite(trigger, bbio.HIGH)
    time.sleep(DECPULSETRIGGER)
    bbio.digitalWrite(trigger, bbio.LOW)

    # Wait for echo to go high (or timeout)
    intcountdown = INTTIMEOUT

    while (bbio.digitalRead(echo) == 0 and intcountdown > 0):
        intcountdown = intcountdown - 1

    # If echo is high
    if intcountdown > 0:

        # Start timer and init timeout countdown
        echostart = time.time()
        intcountdown = INTTIMEOUT

        # Wait for echo to go low (or timeout)
        while (bbio.digitalRead(echo) == 1 and intcountdown > 0):
            intcountdown = intcountdown - 1

        # Stop timer
        echoend = time.time()

        # Echo duration
        echoduration = echoend - echostart
        intdistance = (echoduration*1000000) / 58.0
        return intdistance
Beispiel #2
0
def measure(trigger, echo):
    bbio.digitalWrite(trigger, bbio.HIGH)
    time.sleep(DECPULSETRIGGER)
    bbio.digitalWrite(trigger, bbio.LOW)

    # Wait for echo to go high (or timeout)
    intcountdown = INTTIMEOUT

    while (bbio.digitalRead(echo) == 0 and intcountdown > 0):
        intcountdown = intcountdown - 1

    # If echo is high
    if intcountdown > 0:

        # Start timer and init timeout countdown
        echostart = time.time()
        intcountdown = INTTIMEOUT

        # Wait for echo to go low (or timeout)
        while (bbio.digitalRead(echo) == 1 and intcountdown > 0):
            intcountdown = intcountdown - 1

        # Stop timer
        echoend = time.time()

        # Echo duration
        echoduration = echoend - echostart
        intdistance = (echoduration * 1000000) / 58.0
        return intdistance
Beispiel #3
0
 def is_activated(self):
     """
     Tells the user if the button is activated or not.
     :returns: True if the button is activated, False otherwise.
     :rtype: boolean
     """
     return io.digitalRead(self.__pin) == io.HIGH
Beispiel #4
0
def onPinChange():
    global count
    global state

    new_state = bbio.digitalRead(PIN)
    if new_state == state:
        print "Got pin change by value is same; missed one?"
    else:
        state = new_state
        count += 1
Beispiel #5
0
def start(freq):
    global count
    global state

    pwm_run = open(PWM_DIR+'run', 'w')
    pwm_run.write('0')
    pwm_duty = open(PWM_DIR+'duty_ns', 'w')
    pwm_duty.write('0')
    pwm_period = open(PWM_DIR+'period_ns', 'w')
    period = round((1.0/freq)*1e9)
    duty = round(period/2.0)
    pwm_period.write('%d' % period)
    pwm_period.close()
    pwm_duty.write('%d' % duty)
    pwm_duty.close()
    count = 0
    state = bbio.digitalRead(PIN);
    bbio.attachInterrupt(PIN, onPinChange, bbio.BOTH);
    pwm_run.write('1')
    pwm_run.close()