Skip to content

[PXCT-843] Renamed examples + Added comments #28

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <Modulino.h>

// Create a ModulinoButtons object
ModulinoButtons buttons;

bool button_a = false;
Expand All @@ -16,15 +17,17 @@ bool button_c = false;

void setup() {
Serial.begin(9600);
// Initialize Modulino I2C communication
Modulino.begin();
// Detect and connect to buttons module
buttons.begin();
//function to control the LEDs on top of each button
// Turn on the LEDs above buttons A, B, and C
buttons.setLeds(true, true, true);
}
void loop() {
//request new data from the Modulino buttons
// Check for new button events, returns true when button state changes
if (buttons.update()) {
//Check if the buttons has been pressed
// Check which button was pressed (0=A, 1=B, 2=C)
if (buttons.isPressed(0)) {
Serial.println("Button A pressed!");
} else if (buttons.isPressed(1)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,25 @@

#include <Modulino.h>

// Create a ModulinoBuzzer object
ModulinoBuzzer buzzer;

int frequency = 440;
int duration = 1000;

void setup(){
// Initialize Modulino I2C communication
Modulino.begin();
// Detect and connect to buzzer module
buzzer.begin();
}

void loop(){

// Play tone at specified frequency and duration
buzzer.tone(frequency, duration);
delay(1000);
// Stop the tone (0 frequency)
buzzer.tone(0, duration);
delay(1000);

Expand Down
9 changes: 7 additions & 2 deletions examples/Modulino_Buzzer/Simple_melody/Simple_melody.ino
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,25 @@

#include <Modulino.h>

// Create a ModulinoBuzzer object
ModulinoBuzzer buzzer;

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

void setup() {
// Initialize Modulino I2C communication
Modulino.begin();
// Detect and connect to buzzer module
buzzer.begin();
}

void loop() {

// Play each note in the melody
for (int i = 0; i < 8; i++) {
// Get current note frequency
int note = melody[i];

// Play the note for 250ms
buzzer.tone(note, 250);
delay(250);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,21 @@

#include "Modulino.h"

// Create a ModulinoDistance object
ModulinoDistance distance;

void setup() {
Serial.begin(9600);
// Initialize Modulino I2C communication
Modulino.begin();
// Detect and connect to distance sensor module
distance.begin();
}

void loop() {
// Check if new distance measurement is available
if (distance.available()) {
// Get the latest distance measurement in millimeters
int measure = distance.get();
Serial.println(measure);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,43 @@

#include "Modulino.h"

// Create objects for the modules
ModulinoKnob encoder;
ModulinoPixels leds;
ModulinoButtons buttons;

void setup() {
// put your setup code here, to run once:
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 the position of the encoder with the set function
// 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));
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,21 @@

#include <Modulino.h>

// Create a ModulinoKnob object
ModulinoKnob knob;

void setup() {
Serial.begin(9600);
// Initialize Modulino I2C communication
Modulino.begin();
// Detect and connect to knob module
knob.begin();
}

void loop(){
// Get the current position value of the knob
int position = knob.get();
// Check if the knob has been pressed (clicked)
bool click = knob.isPressed();

Serial.print("Current position is: ");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "Modulino.h"

// Create a ModulinoMovement
ModulinoMovement movement;

float x;
Expand All @@ -16,13 +17,17 @@ float z;

void setup() {
Serial.begin(9600);
// Initialize Modulino I2C communication
Modulino.begin();
// Detect and connect to movement sensor module
movement.begin();
}

void loop() {
// Read new acceleration data from the sensor
movement.update();

// Get the acceleration values for each axis (in Gs)
x = movement.getX();
y = movement.getY();
z = movement.getZ();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,25 @@

#include <Modulino.h>

// Create a ModulinoPixels object
ModulinoPixels leds;

int brightness = 25;

void setup(){
// Initialize Modulino I2C communication
Modulino.begin();
// Detect and connect to pixels module
leds.begin();
}

void loop(){
//Set all LEDs blue
// Set all 8 LEDs to blue color
for (int i = 0; i < 8; i++) {
// Set each LED (index, color, brightness)
// Available colors: RED, BLUE, GREEN, VIOLET, WHITE
leds.set(i, BLUE, brightness);
// Update the physical LEDs with new settings
leds.show();
}
}
10 changes: 8 additions & 2 deletions examples/Modulino_Pixels/Simple_Animation/Simple_Animation.ino
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,24 @@

#include <Modulino.h>

// Create a ModulinoPixels object for the LED array
ModulinoPixels leds;

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

int brightness = 25;

void setup() {
// Initialize Modulino I2C communication
Modulino.begin();
// Detect and connect to pixels module
leds.begin();
}

void loop() {

// Light up LEDs in different colors
// Available colors: RED, BLUE, GREEN, VIOLET, WHITE
for (int i = 0; i < 8; i++) {
if (i == 0 || i == 1) {
setPixel(i, RED);
Expand All @@ -37,7 +42,8 @@ void loop() {
delay(25);

}


// Turn off all LEDs one by one
for (int i = 0; i < 8; i++) {
setPixel(i, OFF);
delay(25);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
#include "ArduinoGraphics.h"
#include "Arduino_LED_Matrix.h"

// Create a ModulinoThermo object
ModulinoThermo thermo;
// Create an object to control the LED matrix on UNO R4 WiFi
ArduinoLEDMatrix matrix;

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

// Initialize Modulino I2C communication
Modulino.begin();
// Detect and connect to temperature/humidity sensor module
thermo.begin();

// Initialize the LED matrix
matrix.begin();
delay(100);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,20 @@ ModulinoThermo thermo;
void setup(){
Serial.begin(9600);

// Call all necessary .begin() function
// Initialize Modulino I2C communication
Modulino.begin();
// Detect and connect to temperature/humidity sensor module
thermo.begin();
}

void loop(){

// Read temperature in Celsius from the sensor
float celsius = thermo.getTemperature();

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

// Read humidity percentage from the sensor
float humidity = thermo.getHumidity();

Serial.print("Temperature (C) is: ");
Expand Down
17 changes: 13 additions & 4 deletions examples/Utilities/Modulino_PlugNPlay/Modulino_PlugNPlay.ino
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "Modulino.h"

// Create objects for all Modulino modules
ModulinoButtons buttons;
ModulinoBuzzer buzzer;
ModulinoPixels leds;
Expand All @@ -19,15 +20,14 @@ ModulinoThermo thermo;
void setup() {

Serial.begin(115200);
// Initialize Modulino I2C communication
Modulino.begin();

// Detect and connect to all modules
distance.begin();

buttons.begin();
encoder.begin();
buzzer.begin();
leds.begin();

imu.begin();
thermo.begin();
}
Expand All @@ -43,14 +43,17 @@ void loop() {
float x;
float y;
float z;

// Cycle through LED patterns when encoder is pressed
if (encoder.isPressed()) {
skip = (skip + 1) % 5;
}

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

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

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

// Check for button presses
if (buttons.update()) {
// Button A: Red LED and 440Hz tone
if (buttons.isPressed(0)) {
leds.set(1 + skip, RED, 100);
buzzer.tone(440 + pitch, 1000);
} else {
leds.clear(1 + skip);
}
// Button B: Blue LED and 880Hz tone
if (buttons.isPressed(1)) {
leds.set(2 + skip, BLUE, 100);
buzzer.tone(880 + pitch, 1000);
} else {
leds.clear(2 + skip);
}
// Button C: Green LED and 1240Hz tone
if (buttons.isPressed(2)) {
leds.set(3 + skip, GREEN, 100);
buzzer.tone(1240 + pitch, 1000);
} else {
leds.clear(3 + skip);
}
// Update the LEDs
leds.show();
}
}
Loading