Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add example: LedSynth #14

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions examples/Modulino_Knob/LedSynth/LedSynth/LedSynth.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#include <Modulino.h>

//Maximum and minimum encoder values
#define KNOBMAX 7
#define KNOBMIN 0

//Modulino boards
ModulinoKnob knob;
ModulinoPixels leds;
ModulinoBuzzer buzzer;

void setup() {
//Inizialize modulino boards
Modulino.begin();
knob.begin();
knob.set(0);
buzzer.begin();
leds.begin();
}

int i;
//Encoder value and button status
int knobPosition = 0;
bool knobClick = false;

void loop() {
//Acquire current encoder value
knobPosition = knob.get();

/*Check if encoder value is outside of range
and if so keep it in range*/
if (knobPosition > KNOBMAX) {
knobPosition = KNOBMAX;
} else if (knobPosition <= KNOBMIN) {
knobPosition = KNOBMIN;
}

//Set to be lit the LED corresponding to encoder value
leds.set(knobPosition, RED, 100);

//Shut of the other LEDs
for (i = KNOBMIN; i <= KNOBMAX; i++) {
if (i != knobPosition) {
leds.clear(i);
}
}

//Lit the LED
leds.show();

//Check if encoder button is pressed
knobClick = knob.isPressed();

/*If the encoder button is pressed reproduce sound
with pitch equal to encoder value * 100Hz + 200 Hz*/
if (knobClick) {
buzzer.tone(knobPosition * 100 + 200, 10);
}
}
Loading