File tree 1 file changed +59
-0
lines changed
examples/Modulino_Knob/LedSynth/LedSynth
1 file changed +59
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments