|
| 1 | +# Arduino Modulino® Library |
| 2 | + |
| 3 | +The **Modulino** library is designed to simplify integration with various Modulino. It supports a variety of modules, such as motion sensors, buttons, buzzers, LED displays, and more, all through an I2C (`Wire`) interface. |
| 4 | + |
| 5 | +## Hardware Compatibility |
| 6 | + |
| 7 | +The library is compatible with Arduino boards that support I2C (`Wire`) communication. |
| 8 | + |
| 9 | +Each Modulino has a fixed I2C address assigned by default. If you wish to change the I2C address, you can refer to the [Utilities](#utilities) section. |
| 10 | + |
| 11 | +## Main Features |
| 12 | + |
| 13 | +The **Modulino** library supports the following hardware modules: |
| 14 | + |
| 15 | +- **Buttons (`ModulinoButtons`)**: Read the state of buttons and control the associated LEDs. |
| 16 | +- **Buzzer (`ModulinoBuzzer`)**: Activate and deactivate the buzzer and set its frequency. |
| 17 | +- **LEDs (`ModulinoPixels`)**: Control RGB LEDs with customizable display modes. |
| 18 | +- **Knob (`ModulinoKnob`)**: Read the value of a rotary encoder. |
| 19 | +- **Motion (`ModulinoMovement`)**: Interface with the LSM6DSOX IMU sensor to get acceleration values. |
| 20 | +- **Temperature & Humidity (`ModulinoThermo`)**: Get temperature and humidity readings from the HS300x sensor. |
| 21 | +- **Distance (`ModulinoDistance`)**: Measures distance using a Time-of-Flight (ToF) sensor (VL53L0x). |
| 22 | + |
| 23 | +## Library Initialization |
| 24 | + |
| 25 | +To initialize the **Modulino** library, include the header file and call the `begin()` method. This will set up the I2C communication and prepare the library for use with the modules. |
| 26 | + |
| 27 | +```cpp |
| 28 | +#include <Modulino.h> |
| 29 | +Modulino.begin(); // Initialize the Modulino library |
| 30 | +``` |
| 31 | + |
| 32 | +## Supported Modules |
| 33 | + |
| 34 | +You can initialize a Modulino board easily. The basic setup requires just a call to the `begin()` method for each module. For example: |
| 35 | + |
| 36 | +```cpp |
| 37 | +ModulinoType modulino_name; |
| 38 | +modulino_name.begin(); // Initialize the ModulinoType module |
| 39 | +``` |
| 40 | + |
| 41 | +### ModulinoButtons |
| 42 | +Manages the state of three buttons and controls their associated LED states. You can read the state of each button and send commands to turn the LEDs on/off. |
| 43 | + |
| 44 | + |
| 45 | + |
| 46 | +```cpp |
| 47 | +ModulinoButtons buttons; |
| 48 | +buttons.begin(); |
| 49 | +buttons.setLeds(true, false, true); // Turn on LED 1 and LED 3 |
| 50 | +``` |
| 51 | + |
| 52 | +### ModulinoBuzzer |
| 53 | +Allows you to emit sounds through the buzzer. You can set the frequency and duration of the sound. |
| 54 | + |
| 55 | + |
| 56 | + |
| 57 | +```cpp |
| 58 | +ModulinoBuzzer buzzer; |
| 59 | +buzzer.begin(); |
| 60 | +buzzer.tone(440, 1000); // 440Hz frequency for 1000ms |
| 61 | +``` |
| 62 | + |
| 63 | +### ModulinoPixels |
| 64 | +Controls an array of 8 RGB LEDs, allowing you to set the colors and brightness. You can also clear individual LEDs or the entire array. |
| 65 | + |
| 66 | + |
| 67 | + |
| 68 | +```cpp |
| 69 | +ModulinoPixels leds; |
| 70 | +leds.set(0, ModulinoColor(255, 0, 0)); // Set the first LED (Position: 0) to red |
| 71 | +leds.show(); // Display the LEDs |
| 72 | +``` |
| 73 | + |
| 74 | +### ModulinoKnob |
| 75 | +Manages a rotary encoder, allowing you to read the potentiometer value and check if the knob is pressed. |
| 76 | + |
| 77 | + |
| 78 | + |
| 79 | +```cpp |
| 80 | +ModulinoKnob knob; |
| 81 | +knob.begin(); |
| 82 | +int16_t value = knob.get(); // Get the value of the encoder |
| 83 | +``` |
| 84 | + |
| 85 | +### ModulinoMovement |
| 86 | +Interfaces with the LSM6DSOX IMU sensor to get acceleration readings. |
| 87 | + |
| 88 | + |
| 89 | + |
| 90 | +```cpp |
| 91 | +ModulinoMovement movement; |
| 92 | +movement.begin(); |
| 93 | +float x = movement.getX(); |
| 94 | +``` |
| 95 | + |
| 96 | +### ModulinoThermo |
| 97 | +Reads temperature and humidity data from the HS300x sensor. |
| 98 | + |
| 99 | + |
| 100 | + |
| 101 | +```cpp |
| 102 | +ModulinoThermo thermo; |
| 103 | +thermo.begin(); |
| 104 | +float temperature = thermo.getTemperature(); |
| 105 | +float humidity = thermo.getHumidity(); |
| 106 | +``` |
| 107 | + |
| 108 | +### ModulinoDistance |
| 109 | +Measures distance using a ToF (Time-of-Flight) sensor. |
| 110 | + |
| 111 | + |
| 112 | + |
| 113 | +```cpp |
| 114 | +ModulinoDistance distance; |
| 115 | +distance.begin(); |
| 116 | +float distanceValue = distance.get(); |
| 117 | +``` |
| 118 | + |
| 119 | +## Example Usage |
| 120 | + |
| 121 | +Here’s an example of how to use some Modulino in a program: |
| 122 | + |
| 123 | +```cpp |
| 124 | +// This sketch demonstrates how to use the Modulino library to control buttons, LEDs, and a buzzer. |
| 125 | +// It listens for a button press (Button A), turns on the LED 0, and plays a sound through the buzzer when pressed. |
| 126 | + |
| 127 | +#include <Modulino.h> |
| 128 | + |
| 129 | +ModulinoButtons buttons; // Declare a Buttons Modulino |
| 130 | +ModulinoPixels leds; // Declare a Pixels Modulino |
| 131 | +ModulinoBuzzer buzzer; // Declare a Buzzer Modulino |
| 132 | + |
| 133 | +int frequency = 440; // Set frequency to 440Hz |
| 134 | +int duration = 1000; // Set duration to 1000ms |
| 135 | + |
| 136 | +void setup() { |
| 137 | + Serial.begin(9600); |
| 138 | + |
| 139 | + Modulino.begin(); // Initialize the Modulino library |
| 140 | + |
| 141 | + buttons.begin(); // Initialize the Buttons module |
| 142 | + leds.begin(); // Initialize the Pixels module |
| 143 | + buzzer.begin(); // Initialize the Buzzer module |
| 144 | +} |
| 145 | + |
| 146 | +void loop() { |
| 147 | + if (buttons.update()) { // Update the button states |
| 148 | + if (buttons.isPressed(0)) { // Check if Button A (button 0) is pressed |
| 149 | + Serial.println("Button A pressed!"); |
| 150 | + leds.set(0, RED); // Turn on LED 0 to red |
| 151 | + leds.show(); |
| 152 | + |
| 153 | + buzzer.tone(frequency, duration); // Play buzzer sound with the specified frequency and duration |
| 154 | + delay(duration); |
| 155 | + } else { |
| 156 | + leds.clear(0); // Turn off LED 0 |
| 157 | + leds.show(); |
| 158 | + } |
| 159 | + } |
| 160 | +} |
| 161 | +``` |
| 162 | + |
| 163 | +## Examples |
| 164 | + |
| 165 | +The examples folder is organized by Modulino type. Each module has its own folder with example sketches that demonstrate both basic and advanced usage (where applicable). |
| 166 | + |
| 167 | +You can explore the examples [here](../examples). |
| 168 | + |
| 169 | +### Utilities |
| 170 | + |
| 171 | +In the [Utilities](../examples/Utilities) folder, you will find programs designed to help you manage and manipulate the Modulino: |
| 172 | + |
| 173 | +- [AddressChanger](../examples/Utilities/AddressChanger/): This program allows you to change the I2C address of a Modulino module. It’s helpful when you need to reassign addresses to avoid conflicts or organize your I2C network. |
| 174 | + |
| 175 | +## API |
| 176 | + |
| 177 | +The API documentation can be found [here](./api.md). |
| 178 | + |
| 179 | +## License |
| 180 | + |
| 181 | +This library is released under the [MPL-2.0 license](../LICENSE). |
0 commit comments