Skip to content

Commit 53c079c

Browse files
committed
feat(buttons): allow isPressed() to accept 'A', 'B', 'C' as input
Added support for character and string-based input to `isPressed()` in `ModulinoButtons`, so it now accepts both index (0–2) and letter identifiers (`'A'`, `'B'`, `'C'`) matching the physical button labeling. Closes #3
1 parent fd69d03 commit 53c079c

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

.gitignore

+28
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 (se lo usi)
28+
.vscode/

src/Modulino.h

+19
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,17 @@ class ModulinoButtons : public Module {
127127
PinStatus isPressed(int index) {
128128
return last_status[index] ? HIGH : LOW;
129129
}
130+
PinStatus isPressed(char button) {
131+
int index = buttonToIndex(button);
132+
if (index < 0) return LOW;
133+
return isPressed(index);
134+
}
135+
PinStatus isPressed(const char *button) {
136+
if (button == nullptr || button[0] == '\0' || button[1] != '\0') {
137+
return LOW;
138+
}
139+
return isPressed(button[0]);
140+
}
130141
bool update() {
131142
uint8_t buf[3];
132143
auto res = read((uint8_t*)buf, 3);
@@ -154,6 +165,14 @@ class ModulinoButtons : public Module {
154165
}
155166
private:
156167
bool last_status[3];
168+
int buttonToIndex(char button) {
169+
switch (toupper(button)) {
170+
case 'A': return 0;
171+
case 'B': return 1;
172+
case 'C': return 2;
173+
default: return -1;
174+
}
175+
}
157176
protected:
158177
uint8_t match[1] = { 0x7C }; // same as fw main.c
159178
};

0 commit comments

Comments
 (0)