Skip to content

Commit 0a180c4

Browse files
committed
Add example: LedSynth
1 parent a61a491 commit 0a180c4

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#include <Modulino.h>
2+
3+
//Maximum and minimum encoder values
4+
#define KNOBMAX 7
5+
#define KNOBMIN 0
6+
7+
//Modulino boards
8+
ModulinoKnob knob;
9+
ModulinoPixels leds;
10+
ModulinoBuzzer buzzer;
11+
12+
void setup() {
13+
//Inizialize modulino boards
14+
Modulino.begin();
15+
knob.begin();
16+
knob.set(0);
17+
buzzer.begin();
18+
leds.begin();
19+
}
20+
21+
int i;
22+
//Encoder value and button status
23+
int knobPosition = 0;
24+
bool knobClick = false;
25+
26+
void loop() {
27+
//Acquire current encoder value
28+
knobPosition = knob.get();
29+
30+
/*Check if encoder value is outside of range
31+
and if so keep it in range*/
32+
if (knobPosition > KNOBMAX) {
33+
knobPosition = KNOBMAX;
34+
} else if (knobPosition <= KNOBMIN) {
35+
knobPosition = KNOBMIN;
36+
}
37+
38+
//Set to be lit the LED corresponding to encoder value
39+
leds.set(knobPosition, RED, 100);
40+
41+
//Shut of the other LEDs
42+
for (i = KNOBMIN; i <= KNOBMAX; i++) {
43+
if (i != knobPosition) {
44+
leds.clear(i);
45+
}
46+
}
47+
48+
//Lit the LED
49+
leds.show();
50+
51+
//Check if encoder button is pressed
52+
knobClick = knob.isPressed();
53+
54+
/*If the encoder button is pressed reproduce sound
55+
with pitch equal to encoder value * 100Hz + 200 Hz*/
56+
if (knobClick) {
57+
buzzer.tone(knobPosition * 100 + 200, 10);
58+
}
59+
}

0 commit comments

Comments
 (0)