-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathModulino_PlugNPlay.ino
79 lines (65 loc) · 1.48 KB
/
Modulino_PlugNPlay.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include "Modulino.h"
ModulinoButtons buttons;
ModulinoBuzzer buzzer;
ModulinoPixels leds;
ModulinoKnob encoder;
ModulinoDistance distance;
ModulinoMovement imu;
ModulinoThermo thermo;
void setup() {
Serial.begin(115200);
Modulino.begin();
distance.begin();
buttons.begin();
encoder.begin();
buzzer.begin();
leds.begin();
imu.begin();
thermo.begin();
}
int skip = 0;
int pitch = 0;
bool a = false;
bool b = false;
bool c = false;
void loop() {
float x;
float y;
float z;
if (encoder.isPressed()) {
skip = (skip + 1) % 5;
}
pitch = encoder.get() + distance.get();
if (Serial.available() && Serial.read() == 's') {
imu.update();
Serial.print("IMU: x ");
Serial.print(imu.getX(), 3);
Serial.print("\ty ");
Serial.print(imu.getY(), 3);
Serial.print("\tz ");
Serial.println(imu.getZ(), 3);
Serial.print("Humidity: " + String(thermo.getHumidity()));
Serial.println("\tTemperature: " + String(thermo.getTemperature()));
}
if (buttons.update()) {
if (buttons.isPressed(0)) {
leds.set(1 + skip, RED, 100);
buzzer.tone(440 + pitch, 1000);
} else {
leds.clear(1 + skip);
}
if (buttons.isPressed(1)) {
leds.set(2 + skip, BLUE, 100);
buzzer.tone(880 + pitch, 1000);
} else {
leds.clear(2 + skip);
}
if (buttons.isPressed(2)) {
leds.set(3 + skip, GREEN, 100);
buzzer.tone(1240 + pitch, 1000);
} else {
leds.clear(3 + skip);
}
leds.show();
}
}