Skip to content

Instantly share code, notes, and snippets.

@Enkerli
Created May 21, 2016 03:11
Show Gist options
  • Save Enkerli/650661473e7eb045e93e41ed9630d74f to your computer and use it in GitHub Desktop.
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.
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