Created
November 1, 2018 19:59
-
-
Save janhajk/4284b5e59e4f3518c006e38b18622b48 to your computer and use it in GitHub Desktop.
This file contains 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 channel = 0; | |
int resolution = 8; | |
void setup() { | |
Serial.begin(115200); | |
ledcSetup(channel, 2000, resolution); | |
ledcAttachPin(12, channel); | |
} | |
void loop() { | |
ledcWrite(channel, 20); | |
for (int key = 44; key < 80; key = key + 1){ | |
tone(key, 50); | |
} | |
} | |
void tone (int key, int leng) { | |
ledcWriteTone(channel, frequencyFromKey(key)); | |
delay(leng); | |
} | |
// Gibt die Hz zurück anahnd der Klaviertasten-Nr. | |
// siehe : https://de.wikipedia.org/wiki/Frequenzen_der_gleichstufigen_Stimmung | |
int frequencyFromKey (float key) { | |
float hz = 0; | |
hz = pow(2, ((key-49)/12)) * 440; | |
Serial.println(hz); | |
return hz; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment