/*i9.Esboce o diagrama de ligações de um piezo e um potenciómetro ligado ao
arduino. Realize código que permite regular através do potenciómetro a
frequência no piezo P1 entre 500-1500 Hz.
Buzzer
https://create.arduino.cc/projecthub/SURYATEJA/use-a-buzzer-module-piezo-speaker-using-arduino-uno-89df45
*/
int analogPin = A0; // potentiometer wiper (middle terminal) connected to analog pin 3
// outside leads to ground and +5V
float val = 0; // variable to store the value read
const int buzzer = 9; //buzzer to arduino pin 9
void setup() {
// put your setup code here, to run once:
Serial.begin(9600); // setup serial
}
void loop() {
// put your main code here, to run repeatedly:
val = analogRead(analogPin); // read the input pin
val = map(val, 0, 1023, 500, 1500); // scale it to use it with the servo (value between 0 and 180)
Serial.println(" Hz");
tone(buzzer, val);
delay(100);
}