Skip to content

Commit 3d48585

Browse files
committed
Fix: restore files 🔥
1 parent 9a2a9cf commit 3d48585

File tree

3 files changed

+97
-1
lines changed

3 files changed

+97
-1
lines changed

.gitignore

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Compiled object files
2+
*.o
3+
*.a
4+
*.so
5+
*.out
6+
7+
# Arduino build folder
8+
build/
9+
*.elf
10+
*.bin
11+
*.hex
12+
*.eep
13+
14+
# Arduino CLI and IDE cache
15+
*.d
16+
*.dep
17+
*.map
18+
*.lst
19+
20+
# MacOS specific
21+
.DS_Store
22+
23+
# Backup files
24+
*~
25+
*.swp
26+
27+
# VS Code
28+
.vscode/
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Modulino Buttons - Basic
3+
*
4+
* This example code is in the public domain.
5+
* Copyright (c) 2025 Arduino
6+
* SPDX-License-Identifier: MPL-2.0
7+
*/
8+
9+
#include <Modulino.h>
10+
11+
// Create a ModulinoButtons object
12+
ModulinoButtons buttons;
13+
14+
bool button_a = true;
15+
bool button_b = true;
16+
bool button_c = true;
17+
18+
void setup() {
19+
Serial.begin(9600);
20+
// Initialize Modulino I2C communication
21+
Modulino.begin();
22+
// Detect and connect to buttons module
23+
buttons.begin();
24+
// Turn on the LEDs above buttons A, B, and C
25+
buttons.setLeds(true, true, true);
26+
}
27+
void loop() {
28+
// Check for new button events, returns true when button state changes
29+
if (buttons.update()) {
30+
// Check which button was pressed (0=A, 1=B, 2=C)
31+
// Also toggle the corresponding LED, for each of the three buttons
32+
if (buttons.isPressed(0)) {
33+
Serial.println("Button A pressed!");
34+
button_a = !button_a;
35+
} else if (buttons.isPressed(1)) {
36+
Serial.println("Button B pressed!");
37+
button_b = !button_b;
38+
} else if (buttons.isPressed(2)) {
39+
Serial.println("Button C pressed!");
40+
button_c = !button_c;
41+
}
42+
43+
// Update the LEDs above buttons, depending on the variables value
44+
buttons.setLeds(button_a, button_b, button_c);
45+
}
46+
}

src/Modulino.h

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,9 @@ class ModulinoKnob : public Module {
243243
bool begin() {
244244
auto ret = Module::begin();
245245
if (ret) {
246-
// check for set() bug
247246
auto _val = get();
247+
_lastPosition = _val;
248+
_lastDebounceTime = millis();
248249
set(100);
249250
if (get() != 100) {
250251
_bug_on_set = true;
@@ -292,6 +293,24 @@ class ModulinoKnob : public Module {
292293
get();
293294
return _pressed;
294295
}
296+
int8_t getDirection() {
297+
unsigned long now = millis();
298+
if (now - _lastDebounceTime < DEBOUNCE_DELAY) {
299+
return 0;
300+
}
301+
int16_t current = get();
302+
int8_t direction = 0;
303+
if (current > _lastPosition) {
304+
direction = 1;
305+
} else if (current < _lastPosition) {
306+
direction = -1;
307+
}
308+
if (direction != 0) {
309+
_lastDebounceTime = now;
310+
_lastPosition = current;
311+
}
312+
return direction;
313+
}
295314
virtual uint8_t discover() {
296315
for (unsigned int i = 0; i < sizeof(match)/sizeof(match[0]); i++) {
297316
if (scan(match[i])) {
@@ -303,6 +322,9 @@ class ModulinoKnob : public Module {
303322
private:
304323
bool _pressed = false;
305324
bool _bug_on_set = false;
325+
int16_t _lastPosition = 0;
326+
unsigned long _lastDebounceTime = 0;
327+
static constexpr unsigned long DEBOUNCE_DELAY = 30;
306328
protected:
307329
uint8_t match[2] = { 0x74, 0x76 };
308330
};

0 commit comments

Comments
 (0)