Created
August 16, 2015 00:58
-
-
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
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
| /* 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