Created
August 13, 2021 18:04
-
-
Save aldrinmartoq/13a065b17cb647e2f036218aa2b1f559 to your computer and use it in GitHub Desktop.
Prototipo de Theremin para Arduino Quest
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
int trig = 12; | |
int echo = 11; | |
// configura los pines del lector de distancia | |
void distancia_setup() { | |
pinMode(trig, OUTPUT); | |
pinMode(echo, INPUT); | |
} | |
// obtiene distancia desde el lector | |
float distancia_leer() { | |
digitalWrite(trig,LOW); | |
delayMicroseconds(10); | |
digitalWrite(trig, HIGH); | |
delayMicroseconds(10); | |
digitalWrite(trig, LOW); | |
float tiempo = pulseIn(echo, HIGH); | |
float distancia = (0.034*tiempo)/2; | |
return distancia; | |
} | |
// muestra la distancia en consola | |
void distancia_mostrar(float distancia) { | |
Serial.print("distancia: "); | |
Serial.println(distancia); | |
} |
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
int buzzer = 8; | |
void sonido_setup() { | |
pinMode(buzzer, OUTPUT); | |
} | |
void sonido_sonar(int frecuencia) { | |
tone(buzzer, frecuencia); | |
} | |
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
// Theremin | |
// Si yo acerco la mano, cambio la frecuencia del parlante | |
// | |
// 1. Leer => obtener la distancia de la mano | |
// TODO: 2 sensores: 1. para la frecuencia y otro para el volumen | |
// 2. Proceso => en base a la distancia, vamos a generar una nota o freq | |
// 3. Actuo => sonar el parlante con esa frecuencia | |
// TODO: cambiar el volumen | |
void consola_setup() { | |
Serial.begin(9600); | |
} | |
void setup() { | |
consola_setup(); | |
distancia_setup(); | |
sonido_setup(); | |
} | |
void loop() { | |
float distancia = distancia_leer(); | |
// mostrar_distancia(distancia); | |
int min_dist = 10; | |
int max_dist = 100; | |
int min_freq = 100; | |
int max_freq = 800; | |
int frecuencia = map(distancia, min_dist, max_dist, max_freq, min_freq); | |
sonido_sonar(frecuencia); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment