Skip to content

Instantly share code, notes, and snippets.

@futureshocked
Created August 16, 2015 00:58
Show Gist options
  • Save futureshocked/985fd771a7513878f144 to your computer and use it in GitHub Desktop.
Save futureshocked/985fd771a7513878f144 to your computer and use it in GitHub Desktop.
A demo of controlling the loudness of a piezo buzzer with a potentiometer
/* FILE NAME
button.py
1. WHAT IT DOES
Reads the value of a potentiometer and controls the loudness of a piezo buzzer via pwm
2. ORIGINAL WORK
Raspberry Full stack 2015, Peter Dalmaris
3. HARDWARE
D11: piezo buzzer
A0: potentiometer
*/
void setup()
{
Serial.begin(9600);
}
void loop()
{
int knobValue = analogRead(A0);
byte pwm = map(knobValue,0,1024,0,125);
Serial.print(knobValue);
Serial.print("-");
Serial.println(pwm);
analogWrite(11, pwm);
delay(1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment