Skip to content

Commit 711d286

Browse files
[PXCT-843] Renamed examples + Added comments (#28)
1 parent 5c5ecc3 commit 711d286

File tree

12 files changed

+85
-16
lines changed

12 files changed

+85
-16
lines changed

examples/Modulino_Buttons/Basic/Basic.ino renamed to examples/Modulino_Buttons/Buttons_Basic/Buttons_Basic.ino

+6-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include <Modulino.h>
1010

11+
// Create a ModulinoButtons object
1112
ModulinoButtons buttons;
1213

1314
bool button_a = false;
@@ -16,15 +17,17 @@ bool button_c = false;
1617

1718
void setup() {
1819
Serial.begin(9600);
20+
// Initialize Modulino I2C communication
1921
Modulino.begin();
22+
// Detect and connect to buttons module
2023
buttons.begin();
21-
//function to control the LEDs on top of each button
24+
// Turn on the LEDs above buttons A, B, and C
2225
buttons.setLeds(true, true, true);
2326
}
2427
void loop() {
25-
//request new data from the Modulino buttons
28+
// Check for new button events, returns true when button state changes
2629
if (buttons.update()) {
27-
//Check if the buttons has been pressed
30+
// Check which button was pressed (0=A, 1=B, 2=C)
2831
if (buttons.isPressed(0)) {
2932
Serial.println("Button A pressed!");
3033
} else if (buttons.isPressed(1)) {

examples/Modulino_Buzzer/Basic/Basic.ino renamed to examples/Modulino_Buzzer/Buzzer_Basic/Buzzer_Basic.ino

+5
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,25 @@
88

99
#include <Modulino.h>
1010

11+
// Create a ModulinoBuzzer object
1112
ModulinoBuzzer buzzer;
1213

1314
int frequency = 440;
1415
int duration = 1000;
1516

1617
void setup(){
18+
// Initialize Modulino I2C communication
1719
Modulino.begin();
20+
// Detect and connect to buzzer module
1821
buzzer.begin();
1922
}
2023

2124
void loop(){
2225

26+
// Play tone at specified frequency and duration
2327
buzzer.tone(frequency, duration);
2428
delay(1000);
29+
// Stop the tone (0 frequency)
2530
buzzer.tone(0, duration);
2631
delay(1000);
2732

examples/Modulino_Buzzer/Simple_melody/Simple_melody.ino

+7-2
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,25 @@
88

99
#include <Modulino.h>
1010

11+
// Create a ModulinoBuzzer object
1112
ModulinoBuzzer buzzer;
1213

14+
// Define melody notes in Hz (C4, G3, G3, A3, G3, rest, B3, C4)
1315
int melody[] = { 262, 196, 196, 220, 196, 0, 247, 262 };
1416

1517
void setup() {
18+
// Initialize Modulino I2C communication
1619
Modulino.begin();
20+
// Detect and connect to buzzer module
1721
buzzer.begin();
1822
}
1923

2024
void loop() {
21-
25+
// Play each note in the melody
2226
for (int i = 0; i < 8; i++) {
27+
// Get current note frequency
2328
int note = melody[i];
24-
29+
// Play the note for 250ms
2530
buzzer.tone(note, 250);
2631
delay(250);
2732

examples/Modulino_Distance/Basic/Basic.ino renamed to examples/Modulino_Distance/Distance_Basic/Distance_Basic.ino

+5
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,21 @@
88

99
#include "Modulino.h"
1010

11+
// Create a ModulinoDistance object
1112
ModulinoDistance distance;
1213

1314
void setup() {
1415
Serial.begin(9600);
16+
// Initialize Modulino I2C communication
1517
Modulino.begin();
18+
// Detect and connect to distance sensor module
1619
distance.begin();
1720
}
1821

1922
void loop() {
23+
// Check if new distance measurement is available
2024
if (distance.available()) {
25+
// Get the latest distance measurement in millimeters
2126
int measure = distance.get();
2227
Serial.println(measure);
2328
}

examples/Modulino_Knob/EncoderSetter/EncoderSetter.ino renamed to examples/Modulino_Knob/Encoder_Setter/Encoder_Setter.ino

+14-2
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,43 @@
88

99
#include "Modulino.h"
1010

11+
// Create objects for the modules
1112
ModulinoKnob encoder;
1213
ModulinoPixels leds;
1314
ModulinoButtons buttons;
1415

1516
void setup() {
16-
// put your setup code here, to run once:
1717
Serial.begin(115200);
18+
// Initialize Modulino I2C communication
1819
Modulino.begin();
20+
// Detect and connect to modules
1921
encoder.begin();
2022
leds.begin();
2123
buttons.begin();
2224
}
2325

2426
void loop() {
27+
// Get current encoder position value
2528
int value = encoder.get();
26-
//Reset the position of the encoder with the set function
29+
// Reset encoder position if out of range (0-100)
2730
if (value > 100 || value < 0) {
2831
encoder.set(0);
2932
}
33+
34+
// Get updated encoder value after possible reset
3035
value = encoder.get();
36+
3137
Serial.println(value);
38+
39+
// Set LED brightness based on encoder value (0-100)
40+
// Available colors: RED, BLUE, GREEN, VIOLET, WHITE
3241
leds.set(1, RED, value);
3342
leds.set(2, GREEN, value);
3443
leds.set(3, BLUE, value);
44+
// Update LEDs with new settings
3545
leds.show();
46+
// Check button states
3647
buttons.update();
48+
// Set button LEDs to match button press states
3749
buttons.setLeds(buttons.isPressed(0), buttons.isPressed(1), buttons.isPressed(2));
3850
}

examples/Modulino_Knob/Basic/Basic.ino renamed to examples/Modulino_Knob/Knob_Basic/Knob_Basic.ino

+5
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,21 @@
88

99
#include <Modulino.h>
1010

11+
// Create a ModulinoKnob object
1112
ModulinoKnob knob;
1213

1314
void setup() {
1415
Serial.begin(9600);
16+
// Initialize Modulino I2C communication
1517
Modulino.begin();
18+
// Detect and connect to knob module
1619
knob.begin();
1720
}
1821

1922
void loop(){
23+
// Get the current position value of the knob
2024
int position = knob.get();
25+
// Check if the knob has been pressed (clicked)
2126
bool click = knob.isPressed();
2227

2328
Serial.print("Current position is: ");

examples/Modulino_Movement/Basic/Basic.ino renamed to examples/Modulino_Movement/Movement_Basic/Movement_Basic.ino

+5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include "Modulino.h"
1010

11+
// Create a ModulinoMovement
1112
ModulinoMovement movement;
1213

1314
float x;
@@ -16,13 +17,17 @@ float z;
1617

1718
void setup() {
1819
Serial.begin(9600);
20+
// Initialize Modulino I2C communication
1921
Modulino.begin();
22+
// Detect and connect to movement sensor module
2023
movement.begin();
2124
}
2225

2326
void loop() {
27+
// Read new acceleration data from the sensor
2428
movement.update();
2529

30+
// Get the acceleration values for each axis (in Gs)
2631
x = movement.getX();
2732
y = movement.getY();
2833
z = movement.getZ();

examples/Modulino_Pixels/Basic/Basic.ino renamed to examples/Modulino_Pixels/Pixels_Basic/Pixels_Basic.ino

+7-1
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,25 @@
88

99
#include <Modulino.h>
1010

11+
// Create a ModulinoPixels object
1112
ModulinoPixels leds;
1213

1314
int brightness = 25;
1415

1516
void setup(){
17+
// Initialize Modulino I2C communication
1618
Modulino.begin();
19+
// Detect and connect to pixels module
1720
leds.begin();
1821
}
1922

2023
void loop(){
21-
//Set all LEDs blue
24+
// Set all 8 LEDs to blue color
2225
for (int i = 0; i < 8; i++) {
26+
// Set each LED (index, color, brightness)
27+
// Available colors: RED, BLUE, GREEN, VIOLET, WHITE
2328
leds.set(i, BLUE, brightness);
29+
// Update the physical LEDs with new settings
2430
leds.show();
2531
}
2632
}

examples/Modulino_Pixels/Simple_Animation/Simple_Animation.ino

+8-2
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,24 @@
88

99
#include <Modulino.h>
1010

11+
// Create a ModulinoPixels object for the LED array
1112
ModulinoPixels leds;
1213

14+
// Define a custom color for turning off LEDs
1315
ModulinoColor OFF(0, 0, 0);
1416

1517
int brightness = 25;
1618

1719
void setup() {
20+
// Initialize Modulino I2C communication
1821
Modulino.begin();
22+
// Detect and connect to pixels module
1923
leds.begin();
2024
}
2125

2226
void loop() {
23-
27+
// Light up LEDs in different colors
28+
// Available colors: RED, BLUE, GREEN, VIOLET, WHITE
2429
for (int i = 0; i < 8; i++) {
2530
if (i == 0 || i == 1) {
2631
setPixel(i, RED);
@@ -37,7 +42,8 @@ void loop() {
3742
delay(25);
3843

3944
}
40-
45+
46+
// Turn off all LEDs one by one
4147
for (int i = 0; i < 8; i++) {
4248
setPixel(i, OFF);
4349
delay(25);

examples/Modulino_Thermo/TemperatureHumidityMatrix/TemperatureHumidityMatrix.ino renamed to examples/Modulino_Thermo/Temperature_Humidity_Matrix/Temperature_Humidity_Matrix.ino

+5
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
#include "ArduinoGraphics.h"
1111
#include "Arduino_LED_Matrix.h"
1212

13+
// Create a ModulinoThermo object
1314
ModulinoThermo thermo;
15+
// Create an object to control the LED matrix on UNO R4 WiFi
1416
ArduinoLEDMatrix matrix;
1517

1618
float temperature = -273.15;
@@ -19,9 +21,12 @@ float humidity = 0.0;
1921
void setup() {
2022
Serial.begin(9600);
2123

24+
// Initialize Modulino I2C communication
2225
Modulino.begin();
26+
// Detect and connect to temperature/humidity sensor module
2327
thermo.begin();
2428

29+
// Initialize the LED matrix
2530
matrix.begin();
2631
delay(100);
2732
}

examples/Modulino_Thermo/Basic/Basic.ino renamed to examples/Modulino_Thermo/Thermo_Basic/Thermo_Basic.ino

+5-2
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,20 @@ ModulinoThermo thermo;
1414
void setup(){
1515
Serial.begin(9600);
1616

17-
// Call all necessary .begin() function
17+
// Initialize Modulino I2C communication
1818
Modulino.begin();
19+
// Detect and connect to temperature/humidity sensor module
1920
thermo.begin();
2021
}
2122

2223
void loop(){
23-
24+
// Read temperature in Celsius from the sensor
2425
float celsius = thermo.getTemperature();
2526

27+
// Convert Celsius to Fahrenheit
2628
float fahrenheit = (celsius * 9 / 5) + 32;
2729

30+
// Read humidity percentage from the sensor
2831
float humidity = thermo.getHumidity();
2932

3033
Serial.print("Temperature (C) is: ");

examples/Utilities/Modulino_PlugNPlay/Modulino_PlugNPlay.ino

+13-4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include "Modulino.h"
1010

11+
// Create objects for all Modulino modules
1112
ModulinoButtons buttons;
1213
ModulinoBuzzer buzzer;
1314
ModulinoPixels leds;
@@ -19,15 +20,14 @@ ModulinoThermo thermo;
1920
void setup() {
2021

2122
Serial.begin(115200);
23+
// Initialize Modulino I2C communication
2224
Modulino.begin();
23-
25+
// Detect and connect to all modules
2426
distance.begin();
25-
2627
buttons.begin();
2728
encoder.begin();
2829
buzzer.begin();
2930
leds.begin();
30-
3131
imu.begin();
3232
thermo.begin();
3333
}
@@ -43,14 +43,17 @@ void loop() {
4343
float x;
4444
float y;
4545
float z;
46-
46+
// Cycle through LED patterns when encoder is pressed
4747
if (encoder.isPressed()) {
4848
skip = (skip + 1) % 5;
4949
}
5050

51+
// Calculate pitch by combining encoder position and distance sensor value
5152
pitch = encoder.get() + (distance.available() ? distance.get() : 0);
5253

54+
// When 's' is received over serial, report sensor data
5355
if (Serial.available() && Serial.read() == 's') {
56+
// Update and report accelerometer values
5457
imu.update();
5558
Serial.print("IMU: x ");
5659
Serial.print(imu.getX(), 3);
@@ -59,29 +62,35 @@ void loop() {
5962
Serial.print("\tz ");
6063
Serial.println(imu.getZ(), 3);
6164

65+
// Report temperature and humidity values
6266
Serial.print("Humidity: " + String(thermo.getHumidity()));
6367
Serial.println("\tTemperature: " + String(thermo.getTemperature()));
6468
}
6569

70+
// Check for button presses
6671
if (buttons.update()) {
72+
// Button A: Red LED and 440Hz tone
6773
if (buttons.isPressed(0)) {
6874
leds.set(1 + skip, RED, 100);
6975
buzzer.tone(440 + pitch, 1000);
7076
} else {
7177
leds.clear(1 + skip);
7278
}
79+
// Button B: Blue LED and 880Hz tone
7380
if (buttons.isPressed(1)) {
7481
leds.set(2 + skip, BLUE, 100);
7582
buzzer.tone(880 + pitch, 1000);
7683
} else {
7784
leds.clear(2 + skip);
7885
}
86+
// Button C: Green LED and 1240Hz tone
7987
if (buttons.isPressed(2)) {
8088
leds.set(3 + skip, GREEN, 100);
8189
buzzer.tone(1240 + pitch, 1000);
8290
} else {
8391
leds.clear(3 + skip);
8492
}
93+
// Update the LEDs
8594
leds.show();
8695
}
8796
}

0 commit comments

Comments
 (0)