Skip to content

Instantly share code, notes, and snippets.

@HectorTorres
Created May 29, 2017 21:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HectorTorres/44fcf28e58005b9e1428d3701ccbeeb0 to your computer and use it in GitHub Desktop.
Save HectorTorres/44fcf28e58005b9e1428d3701ccbeeb0 to your computer and use it in GitHub Desktop.
buzzer arduino uno
int salida = 0; //declaracion de puerto y nombre
int potenciometro = A0; // declaracion de puerto y nombre (ADC)
float lectura; // se utiliza la variable flotante para tener una mejor lectura de numero probenientes del potenciometro
int FreqMin = 100; // frecuencias a las que quieres osile el sonido
int FreqMax = 1000;
void setup() {
pinMode(salida, OUTPUT); // declaracion de la variable
pinMode(potenciometro, INPUT); // declaracion de la variable
}
void loop() {
lectura = analogRead(potenciometro);
float frecuencia = map(lectura, 0, 1023, FreqMin, FreqMax);
tone (salida, frecuencia, 300); //De aquí borrar el "300" si se quiere un tono continuo
delay(500); // Borrar esta línea completa si se quiere un tono continuo
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment