Example #1
0
def buzz(input_for_period,input_for_length,buzzer_pin):
    while True:
        # Typical piezoelectric buzzer frequencies range from 500-4000Hz, so period has to range from 250 us to 2000 us
        period = helpers.map_range(input_val[input_for_period],1,1000,250,2000)
        # Set the period of the buzzer and the duty to 50% of the period through pwm.write
        # pwm.write is the correct way to use pwm in Zerynth. It is similar at analogWrite in Arduino Wiring, but sounds better
        # Note that in pwm.write we will use MICROS so every sec is 1000000 micros
        # // is the int division, pwm.write period doesn't accept floats
        pwm.write(buzzer_pin,period,period//2,MICROS)
        # Set the length of the sleep to create a "beat" effect (from 1 to 300 ms). The default time unit of sleep function is MILLIS
        length = helpers.map_range(input_val[input_for_length],1,1000,1,300)
        sleep(length)
Example #2
0
def buzz(input_for_period,input_for_length,buzzer_pin):
    while True:
        # Typical piezoelectric buzzer frequencies range from 500-4000Hz, so period has to range from 250 us to 2000 us
        period = helpers.map_range(input_val[input_for_period],1,1000,250,2000)
        # Set the period of the buzzer and the duty to 50% of the period through pwm.write
        # pwm.write is the correct way to use pwm in VIPER. It is similar at analogWrite in Arduino Wiring, but sounds better
        # Note that in pwm.write we will use MICROS so every sec is 1000000 micros
        # // is the int division, pwm.write period doesn't accept floats
        pwm.write(buzzer_pin,period,period//2,MICROS)
        # Set the length of the sleep to create a "beat" effect (from 1 to 300 ms). The default time unit of sleep function is MILLIS
        length = helpers.map_range(input_val[input_for_length],1,1000,1,300)
        sleep(length)
Example #3
0
def blink(input_for_delay,led_pin):
    while True:
        # Set the delay from 1 to 500 ms
        delay = helpers.map_range(input_val[input_for_delay],1,1000,1,500) 
        digitalWrite(led_pin,HIGH)      # turn the LED ON by making the voltage HIGH
        sleep(delay)                    # wait for 'delay' ms
        digitalWrite(led_pin,LOW)       # turn the LED OFF by making the voltage LOW
        sleep(delay)                    # wait for 'delay' ms
Example #4
0
def blink(input_for_delay,led_pin):
    while True:
        # Set the delay from 1 to 500 ms
        delay = helpers.map_range(input_val[input_for_delay],1,1000,1,500) 
        digitalWrite(led_pin,HIGH)      # turn the LED ON by making the voltage HIGH
        sleep(delay)                    # wait for 'delay' ms
        digitalWrite(led_pin,LOW)       # turn the LED OFF by making the voltage LOW
        sleep(delay)                    # wait for 'delay' ms
Example #5
0
def sampling():
    global input_val
    while True:
        input_val['pot_val'] = helpers.map_range(adc.read(pot_pin),0,4000,1,1000)      
        input_val['prox_val'] = helpers.map_range(adc.read(prox_pin),300,3800,1,1000)
        sleep(50)
Example #6
0
def sampling():
    global input_val
    while True:
        input_val['pot_val'] = helpers.map_range(adc.read(pot_pin),0,4000,1,1000)      
        input_val['prox_val'] = helpers.map_range(adc.read(prox_pin),300,3800,1,1000)
        sleep(50)