Components and supplies
Arduino Plug and Make Kit
Apps and platforms
Arduino IDE
Project description
Code
Demo
cpp
Arduino Plug and Make Kit All-Modulino Demo
1/* 2 Arduino Plug and Make Kit All-Modulino Demo 3 4 This sketch initializes various Modulino components, including buttons, buzzer, 5 addressable RGB LEDs, encoder, distance sensor, IMU (Inertial Measurement Unit), thermometer, 6 and an LED matrix. The system performs the following tasks: 7 8 - Plays a sequence of musical notes with corresponding LED animations on startup. 9 - Continuously reads and outputs IMU data, temperature, humidity, distance, 10 and encoder position to the Serial Monitor. 11 - Controls the LEDs and buzzer based on button presses, allowing for interactive 12 feedback. 13 14 The heart pattern is displayed on the LED matrix upon initialization. 15 16 Compatibility: 17 - This code is designed to work with the Modulino system components and an 18 Arduino UNO R4 WiFi. 19 20 created 9 Aug 2024 21 by METE HOCA 22*/ 23 24#include "Modulino.h" // Include the Modulino library to access various sensors and components 25#include "Arduino_LED_Matrix.h" // Include the Arduino LED Matrix library for controlling the LED matrix 26 27// Initialize Modulino components and UNO R4 LED Matrix 28ModulinoButtons buttons; 29ModulinoBuzzer buzzer; 30ModulinoPixels leds; 31ModulinoKnob encoder; 32ModulinoDistance distance; 33ModulinoMovement imu; 34ModulinoThermo thermo; 35ArduinoLEDMatrix matrix; 36 37unsigned long previousMillis = 0; // Store the last time the loop ran 38const long interval = 200; // Interval between loop executions in milliseconds 39int notes[] = {262, 294, 330, 349, 392, 440, 494, 523}; // Array of musical notes 40const uint32_t heart[] = {0x3184a444, 0x44042081, 0x100a0040}; // Heart shape pattern 41 42void setup() { 43 Serial.begin(115200); // Start serial communication at 115200 baud 44 45 // Begin Modulino components and LED Matrix 46 Modulino.begin(); 47 distance.begin(); 48 buttons.begin(); 49 encoder.begin(); 50 buzzer.begin(); 51 leds.begin(); 52 imu.begin(); 53 thermo.begin(); 54 matrix.begin(); 55 56 // Play a sequence of tones and light up corresponding LEDs 57 for (int i = 0; i < 8; i++) { 58 buzzer.tone(notes[i], 250); // Play note for 250 ms 59 leds.set(i, GREEN, 5); // Set LED to green at position i 60 leds.show(); // Display the LEDs 61 delay(250); // Wait for 250 ms before moving to the next note 62 } 63 matrix.loadFrame(heart); // Load heart pattern to the LED matrix 64} 65 66void loop() { 67 unsigned long currentMillis = millis(); // Get the current time 68 if (currentMillis - previousMillis >= interval) { 69 previousMillis = currentMillis; // Update the time for the next loop 70 imu.update(); // Update IMU sensor data 71 72 // Print IMU data and temperature/humidity to the serial monitor 73 Serial.print("IMU: X=" + String(imu.getX(), 3) + "\t Y=" + String(imu.getY(), 3) + "\t Z=" + String(imu.getZ(), 3)); 74 Serial.print("\tTemp: " + String(thermo.getTemperature(), 1) + "°C Hum: " + String(thermo.getHumidity(), 0) + "%"); 75 76 // Check if distance sensor data is available, and print it 77 if (distance.available()) Serial.print("\t\tDistance: " + String(distance.get(), 0) + "mm"); else Serial.print("\t\tDistance: N/A"); 78 79 // Get the value from the encoder, reset if out of bounds, and print it 80 int value = encoder.get(); if (value > 100 || value < 0) encoder.set(0); Serial.println("\t\tKnob: " + String(value)); 81 } 82 83 bool LedA, LedB, LedC, LedD; // Variables to store button states for controlling LEDs 84 bool click = encoder.isPressed(); // Check if the encoder button is pressed and store the result in 'click' 85 86 // Control LEDs and buzzer based on button presses 87 if (buttons.update()) { 88 if (buttons.isPressed(0)) {LedA = true;} else {LedA = false;} 89 if (buttons.isPressed(1)) {LedB = true;} else {LedB = false;} 90 if (buttons.isPressed(2)) {LedC = true;} else {LedC = false;} 91 } 92 if(click) {LedD = true;} else {LedD = false;} // Encoder button 93 94 buttons.setLeds(LedA, LedB, LedC); 95 if (LedA) {buzzer.tone(notes[0], 100); leds.set(0, RED, 5); leds.show();} else {leds.set(0, GREEN, 5); leds.show();} 96 if (LedB) {buzzer.tone(notes[1], 100); leds.set(1, RED, 5); leds.show();} else {leds.set(1, GREEN, 5); leds.show();} 97 if (LedC) {buzzer.tone(notes[2], 100); leds.set(2, RED, 5); leds.show();} else {leds.set(2, GREEN, 5); leds.show();} 98 if (LedD) {buzzer.tone(notes[3], 100); leds.set(3, RED, 5); leds.show();} else {leds.set(3, GREEN, 5); leds.show();} 99}
Downloadable files
Arduino Plug and Make Kit All-Modulino Demo
Arduino Plug and Make Kit All-Modulino Demo
Demo.zip
Comments
Only logged in users can leave comments
metehocax
0 Followers
•0 Projects
Table of contents
Intro
0
0