Skip to content

Commit eeb85bd

Browse files
committed
Encoder and distance as theremin
1 parent c913c90 commit eeb85bd

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

examples/Modulino_Theremin/Therem.ino

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include "Modulino.h"
2+
3+
ModulinoBuzzer buzzer;
4+
ModulinoPixels leds;
5+
ModulinoDistance distance;
6+
ModulinoKnob encoder;
7+
8+
9+
void setup() {
10+
11+
Modulino.begin();
12+
encoder.begin();
13+
distance.begin();
14+
buzzer.begin();
15+
Serial.begin(115200);
16+
}
17+
18+
int pitch = 0;
19+
int noteIndex = 0;
20+
21+
//Notes from C to B with #
22+
int note[] = {262, 277, 294, 311, 330, 349, 370, 392, 415, 440, 466, 494};
23+
24+
void loop() {
25+
pitch = distance.get();
26+
noteIndex = encoder.get();
27+
28+
noteIndex = noteIndex % 11;
29+
if (noteIndex < 0){
30+
noteIndex = 0;
31+
}
32+
Serial.println(noteIndex);
33+
34+
buzzer.tone(note[noteIndex] + pitch, 1000);
35+
}

0 commit comments

Comments
 (0)