Created
May 21, 2016 03:11
-
-
Save Enkerli/650661473e7eb045e93e41ed9630d74f to your computer and use it in GitHub Desktop.
Simple #RasPi script to change a passive buzzer’s frequency based on an ultrasound distance sensor.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from gpiozero import * | |
from time import sleep | |
sensor = DistanceSensor(24, 23) | |
n = 0 | |
bz = PWMOutputDevice(18, initial_value=0.4) | |
bz.pulse(fade_in_time=0.3) | |
while True: | |
print('Distance to nearest object is', sensor.distance, 'm') | |
bz.frequency = (sensor.distance*100)+200 | |
sleep(0.5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment