forked from arduino-libraries/Modulino
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEncoder_Setter.ino
50 lines (43 loc) · 1.17 KB
/
Encoder_Setter.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*
* Modulino Knob - Encoder Setter
*
* This example code is in the public domain.
* Copyright (c) 2025 Arduino
* SPDX-License-Identifier: MPL-2.0
*/
#include "Modulino.h"
// Create objects for the modules
ModulinoKnob encoder;
ModulinoPixels leds;
ModulinoButtons buttons;
void setup() {
Serial.begin(115200);
// Initialize Modulino I2C communication
Modulino.begin();
// Detect and connect to modules
encoder.begin();
leds.begin();
buttons.begin();
}
void loop() {
// Get current encoder position value
int value = encoder.get();
// Reset encoder position if out of range (0-100)
if (value > 100 || value < 0) {
encoder.set(0);
}
// Get updated encoder value after possible reset
value = encoder.get();
Serial.println(value);
// Set LED brightness based on encoder value (0-100)
// Available colors: RED, BLUE, GREEN, VIOLET, WHITE
leds.set(1, RED, value);
leds.set(2, GREEN, value);
leds.set(3, BLUE, value);
// Update LEDs with new settings
leds.show();
// Check button states
buttons.update();
// Set button LEDs to match button press states
buttons.setLeds(buttons.isPressed(0), buttons.isPressed(1), buttons.isPressed(2));
}