Skip to content

Commit b4ddf16

Browse files
authored
Merge pull request #49 from arduino-libraries/0.7.0
Add support for new Modulinos
2 parents 061fa32 + f776d2b commit b4ddf16

File tree

17 files changed

+6394
-789
lines changed

17 files changed

+6394
-789
lines changed

.github/workflows/compile-examples.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ jobs:
5353
- name: Arduino_HS300x
5454
- name: Button2
5555
- name: ArduinoGraphics
56+
- name: Arduino_LTR381RGB
5657
5758
enable-deltas-report: true
5859
sketches-report-path: ${{ env.SKETCHES_REPORTS_PATH }}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include "Modulino.h"
2+
3+
ModulinoJoystick joystick;
4+
5+
void setup() {
6+
Serial.begin(9600);
7+
Modulino.begin();
8+
joystick.begin();
9+
}
10+
11+
void loop() {
12+
joystick.update();
13+
14+
if(joystick.isPressed()) {
15+
Serial.println("Pressed");
16+
}
17+
18+
Serial.print("x,y: ");
19+
Serial.print(joystick.getX());
20+
Serial.print(", ");
21+
Serial.println(joystick.getY());
22+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Modulino Latch Relay - 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+
ModulinoLatchRelay relay;
12+
13+
void setup() {
14+
// put your setup code here, to run once:
15+
Modulino.begin();
16+
Serial.begin(115200);
17+
relay.begin();
18+
}
19+
20+
void loop() {
21+
// put your main code here, to run repeatedly:
22+
if (Serial.available()) {
23+
char c = Serial.read();
24+
switch (c) {
25+
case 's':
26+
relay.set();
27+
break;
28+
case 'r':
29+
relay.reset();
30+
break;
31+
case 'x':
32+
auto status = relay.getStatus();
33+
if (status == 0) {
34+
Serial.println("Relay OFF");
35+
}
36+
if (status == 1) {
37+
Serial.println("Relay ON");
38+
}
39+
if (status < 0) {
40+
Serial.println("Relay status unknown");
41+
}
42+
break;
43+
}
44+
}
45+
}
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
#include "Modulino.h"
2+
3+
ModulinoLight light;
4+
5+
// before to run this sketch, change the encoders addresses in order to use more than one encoder
6+
// and set the addresses in the constructor as shown below
7+
ModulinoKnob knob_green;
8+
ModulinoKnob knob_red(0x09);
9+
ModulinoKnob knob_blue(0x0A);
10+
ModulinoPixels leds;
11+
12+
13+
int brightness = 100;
14+
int red = 0;
15+
int green = 0;
16+
int blue = 0;
17+
18+
19+
void setup() {
20+
Serial.begin(9600);
21+
Modulino.begin();
22+
knob_green.begin();
23+
knob_red.begin();
24+
knob_blue.begin();
25+
26+
// set knobs initial positions to 0
27+
knob_red.set(0);
28+
knob_green.set(0);
29+
knob_blue.set(0);
30+
light.begin();
31+
leds.begin();
32+
}
33+
34+
unsigned long start = millis();
35+
void loop() {
36+
knobPressed();
37+
readColors();
38+
updatesColors();
39+
}
40+
41+
void readColors() {
42+
if (red > 255) {
43+
red = 255;
44+
knob_red.set(red);
45+
} else if (red < 0) {
46+
red = 0;
47+
knob_red.set(red);
48+
}
49+
50+
if (green > 255) {
51+
green = 255;
52+
knob_green.set(green);
53+
} else if (green < 0) {
54+
green = 0;
55+
knob_green.set(green);
56+
}
57+
58+
if (blue > 255) {
59+
blue = 255;
60+
knob_blue.set(blue);
61+
} else if (blue < 0) {
62+
blue = 0;
63+
knob_red.set(blue);
64+
}
65+
}
66+
67+
void knobPressed() {
68+
red = knob_red.get();
69+
green = knob_green.get();
70+
blue = knob_blue.get();
71+
bool red_click = knob_red.isPressed();
72+
bool green_click = knob_green.isPressed();
73+
bool blue_click = knob_blue.isPressed();
74+
75+
if (red_click) {
76+
red = 255;
77+
knob_red.set(red);
78+
}
79+
80+
if (green_click) {
81+
green = 255;
82+
knob_green.set(green);
83+
}
84+
85+
if (blue_click) {
86+
blue = 255;
87+
knob_blue.set(blue);
88+
}
89+
90+
if (green_click && blue_click && red_click ) {
91+
red = 0;
92+
knob_red.set(red);
93+
green = 0;
94+
knob_green.set(green);
95+
blue = 0;
96+
knob_blue.set(blue);
97+
} else if (red_click && green_click) {
98+
red = 255;
99+
knob_red.set(red);
100+
green = 255;
101+
knob_green.set(green);
102+
blue = 0;
103+
knob_blue.set(blue);
104+
} else if (red_click && blue_click) {
105+
red = 255;
106+
knob_red.set(red);
107+
green = 0;
108+
knob_green.set(green);
109+
blue = 255;
110+
knob_blue.set(blue);
111+
} else if (green_click && blue_click) {
112+
red = 0;
113+
knob_red.set(red);
114+
green = 255;
115+
knob_green.set(green);
116+
blue = 255;
117+
knob_blue.set(blue);
118+
}
119+
}
120+
121+
void updatesColors() {
122+
ModulinoColor COLOR(red, green, blue);
123+
for (int l = 0; l < 8; l++) {
124+
leds.set(l, COLOR, brightness);
125+
leds.show();
126+
}
127+
light.update();
128+
129+
if (millis() - start > 1000) {
130+
char buffer [50];
131+
int n, a = 3;
132+
n = sprintf (buffer, "%03d", red);
133+
134+
Serial.print("Red:\t");
135+
Serial.print(buffer);
136+
n = sprintf (buffer, "%03d", green);
137+
Serial.print("\tGreen:\t");
138+
Serial.print(buffer);
139+
n = sprintf (buffer, "%03d", blue);
140+
Serial.print("\tBlue:\t");
141+
Serial.print(buffer);
142+
143+
ModulinoColor color = light.getColor();
144+
String colorName = light.getColorApproximate();
145+
Serial.print("\tColor near to:\t");
146+
Serial.print(colorName);
147+
Serial.println();
148+
149+
start = millis();
150+
}
151+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#include "Modulino.h"
2+
3+
ModulinoLight light;
4+
5+
int lux;
6+
int ir;
7+
8+
void setup() {
9+
Serial.begin(9600);
10+
Modulino.begin();
11+
light.begin();
12+
}
13+
14+
void loop() {
15+
light.update();
16+
ModulinoColor color = light.getColor();
17+
String colorName = light.getColorApproximate();
18+
Serial.print("Color near to: ");
19+
Serial.print(colorName);
20+
21+
int r = (0xFF000000 & color) >> 24;
22+
int g = (0x00FF0000 & color) >> 16;
23+
int b = (0x0000FF00 & color) >> 8;
24+
25+
lux = light.getAL();
26+
ir = light.getIR();
27+
28+
Serial.print("\tlight data: ");
29+
Serial.print("\tRed:\t");
30+
Serial.print(r);
31+
Serial.print("\tGreen:\t");
32+
Serial.print(g);
33+
Serial.print("\tBlue:\t");
34+
Serial.print(b);
35+
Serial.print("\tLux:\t");
36+
Serial.print(lux);
37+
Serial.print("\tIR\t");
38+
Serial.println(ir);
39+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include "Modulino.h"
2+
3+
ModulinoVibro vibro;
4+
5+
void setup() {
6+
Modulino.begin();
7+
vibro.begin();
8+
}
9+
10+
void loop() {
11+
// Cycle through vibration intensities from GENTLE to MAXIMUM
12+
// Each intensity increases by 5, lasting 1 seconds each
13+
for (int intensity = GENTLE; intensity <= MAXIMUM; intensity += 5) {
14+
Serial.println(intensity);
15+
vibro.on(1000, true, intensity);
16+
vibro.off();
17+
delay(100);
18+
}
19+
20+
// Two vibration of one second separated by a long pause
21+
// using the blocking on call
22+
delay(1000);
23+
vibro.on(1000);
24+
delay(5000);
25+
vibro.on(1000);
26+
delay(1000);
27+
}

examples/Utilities/AddressChanger/AddressChanger.ino

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,13 +228,19 @@ String pinstrapToName(uint8_t pinstrap) {
228228
switch (pinstrap) {
229229
case 0x3C:
230230
return "Buzzer";
231+
case 0x58:
232+
return "Joystick";
231233
case 0x7C:
232234
return "Buttons";
235+
case 0x28:
236+
return "Opto Relay";
233237
case 0x76:
234238
case 0x74:
235239
return "Encoder";
236240
case 0x6C:
237241
return "Smartleds";
242+
case 0x70:
243+
return "Vibro";
238244
}
239245
return "UNKNOWN";
240246
}

0 commit comments

Comments
 (0)