From cda3d1210d876ceb82d4e792e07cc4d6a0ba9559 Mon Sep 17 00:00:00 2001 From: giulio93 Date: Thu, 27 Jun 2024 11:48:32 +0200 Subject: [PATCH] Encoder and distance as theremin --- .../Modulino_Theremin/Modulino_Theremin.ino | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 examples/Modulino_Theremin/Modulino_Theremin.ino diff --git a/examples/Modulino_Theremin/Modulino_Theremin.ino b/examples/Modulino_Theremin/Modulino_Theremin.ino new file mode 100644 index 0000000..fd79184 --- /dev/null +++ b/examples/Modulino_Theremin/Modulino_Theremin.ino @@ -0,0 +1,32 @@ +#include "Modulino.h" + +ModulinoBuzzer buzzer; +ModulinoDistance distance; +ModulinoKnob encoder; + + +void setup() { + + Modulino.begin(); + encoder.begin(); + distance.begin(); + buzzer.begin(); +} + +int pitch = 0; +int noteIndex = 0; + +//Notes from C to B with # +int note[] = {262, 277, 294, 311, 330, 349, 370, 392, 415, 440, 466, 494}; + +void loop() { + pitch = distance.get(); + noteIndex = encoder.get(); + + noteIndex = noteIndex % 11; + if (noteIndex < 0){ + noteIndex = 0; + } + + buzzer.tone(note[noteIndex] + pitch, 1000); +} \ No newline at end of file