Skip to content

Commit c913c90

Browse files
authored
Merge pull request #7 from arduino-libraries/new_examples
new examples and folder structure
2 parents 4f10376 + 95ec7f6 commit c913c90

File tree

15 files changed

+228
-0
lines changed

15 files changed

+228
-0
lines changed
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include <Modulino.h>
2+
3+
ModulinoButtons buttons;
4+
5+
bool button_a = false;
6+
bool button_b = false;
7+
bool button_c = false;
8+
9+
void setup() {
10+
Serial.begin(9600);
11+
Modulino.begin();
12+
buttons.begin();
13+
//function to control the LEDs on top of each button
14+
buttons.setLeds(true, true, true);
15+
}
16+
void loop() {
17+
//request new data from the Modulino buttons
18+
if (buttons.update()) {
19+
//Check if the buttons has been pressed
20+
if (buttons.isPressed(0)) {
21+
Serial.println("Button A pressed!");
22+
} else if (buttons.isPressed(1)) {
23+
Serial.println("Button B pressed!");
24+
} else if (buttons.isPressed(2)) {
25+
Serial.println("Button C pressed!");
26+
}
27+
}
28+
}
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include <Modulino.h>
2+
3+
ModulinoBuzzer buzzer;
4+
5+
int frequency = 440;
6+
int duration = 1000;
7+
8+
void setup(){
9+
Modulino.begin();
10+
buzzer.begin();
11+
}
12+
13+
void loop(){
14+
15+
buzzer.tone(frequency, duration);
16+
delay(1000);
17+
buzzer.tone(0, duration);
18+
delay(1000);
19+
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include <Modulino.h>
2+
3+
ModulinoBuzzer buzzer;
4+
5+
int melody[] = { 262, 196, 196, 220, 196, 0, 247, 262 };
6+
7+
void setup() {
8+
Modulino.begin();
9+
buzzer.begin();
10+
}
11+
12+
void loop() {
13+
14+
for (int i = 0; i < 8; i++) {
15+
int note = melody[i];
16+
17+
buzzer.tone(note, 250);
18+
delay(250);
19+
20+
}
21+
}
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include "Modulino.h"
2+
3+
ModulinoDistance distance;
4+
5+
void setup() {
6+
Serial.begin(9600);
7+
Modulino.begin();
8+
distance.begin();
9+
}
10+
11+
void loop() {
12+
int measure = distance.get();
13+
Serial.println(measure);
14+
delay(10);
15+
}
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include <Modulino.h>
2+
3+
ModulinoKnob knob;
4+
5+
void setup() {
6+
Serial.begin(9600);
7+
Modulino.begin();
8+
knob.begin();
9+
}
10+
11+
void loop(){
12+
int position = knob.get();
13+
bool click = knob.isPressed();
14+
15+
Serial.print("Current position is: ");
16+
Serial.println(position);
17+
18+
if(click){
19+
Serial.println("Clicked!");
20+
}
21+
22+
}

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

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ void setup() {
1515

1616
void loop() {
1717
int value = encoder.get();
18+
//Reset the position of the encoder with the set function
1819
if (value > 100 || value < 0) {
1920
encoder.set(0);
2021
}
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include "Modulino.h"
2+
3+
ModulinoMovement movement;
4+
5+
float x;
6+
float y;
7+
float z;
8+
9+
void setup() {
10+
Serial.begin(9600);
11+
Modulino.begin();
12+
movement.begin();
13+
}
14+
15+
void loop() {
16+
movement.update();
17+
18+
x = movement.getX();
19+
y = movement.getY();
20+
z = movement.getZ();
21+
22+
Serial.print("Movement data: ");
23+
Serial.print("x ");
24+
Serial.print(x, 3);
25+
Serial.print(" y ");
26+
Serial.print(y, 3);
27+
Serial.print(" z ");
28+
Serial.println(z, 3);
29+
}
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#include <Modulino.h>
2+
3+
ModulinoPixels leds;
4+
5+
int brightness = 25;
6+
7+
void setup(){
8+
Modulino.begin();
9+
leds.begin();
10+
}
11+
12+
void loop(){
13+
//Set all LEDs blue
14+
for (int i = 0; i < 8; i++) {
15+
leds.set(i, BLUE, brightness);
16+
leds.show();
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#include <Modulino.h>
2+
3+
ModulinoPixels leds;
4+
5+
ModulinoColor OFF(0, 0, 0);
6+
7+
int brightness = 25;
8+
9+
void setup() {
10+
Modulino.begin();
11+
leds.begin();
12+
}
13+
14+
void loop() {
15+
16+
for (int i = 0; i < 8; i++) {
17+
if (i == 0 || i == 1) {
18+
setPixel(i, RED);
19+
} else if (i == 2 || i == 3) {
20+
setPixel(i, BLUE);
21+
} else if(i == 4 || i == 5){
22+
setPixel(i, GREEN);
23+
} else if(i == 6 || i == 7){
24+
setPixel(i, VIOLET);
25+
} else if (i == 7 || i == 8) {
26+
setPixel(i, WHITE);
27+
}
28+
29+
delay(25);
30+
31+
}
32+
33+
for (int i = 0; i < 8; i++) {
34+
setPixel(i, OFF);
35+
delay(25);
36+
}
37+
38+
}
39+
40+
void setPixel(int pixel, ModulinoColor color) {
41+
leds.set(pixel, color, brightness);
42+
leds.show();
43+
}
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include <Modulino.h>
2+
3+
// Create object instance
4+
ModulinoThermo thermo;
5+
6+
void setup(){
7+
Serial.begin(9600);
8+
9+
// Call all necessary .begin() function
10+
Modulino.begin();
11+
thermo.begin();
12+
}
13+
14+
void loop(){
15+
16+
float celsius = thermo.getTemperature();
17+
18+
float fahrenheit = (celsius * 9 / 5) + 32;
19+
20+
float humidity = thermo.getHumidity();
21+
22+
Serial.print("Temperature (C) is: ");
23+
Serial.println(celsius);
24+
25+
Serial.print("Temperature (F) is: ");
26+
Serial.println(fahrenheit);
27+
28+
Serial.print("Humidity (rH) is: ");
29+
Serial.println(humidity);
30+
31+
}

0 commit comments

Comments
 (0)