Skip to content

Commit f67eba0

Browse files
committed
Initial import from fw repo
1 parent 71bf758 commit f67eba0

File tree

7 files changed

+2019
-0
lines changed

7 files changed

+2019
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#include "Wire.h"
2+
3+
// Setting new_address to 0 means that the module will get back its original address
4+
const uint8_t new_address = 0;
5+
6+
uint8_t address;
7+
8+
void setup() {
9+
// put your setup code here, to run once:
10+
Wire1.begin();
11+
Serial.begin(115200);
12+
delay(1000);
13+
for (int i = 8; i < 128; i++) {
14+
Wire1.beginTransmission(i);
15+
auto err = Wire1.endTransmission();
16+
if (err == 0) {
17+
Serial.print("Found device at ");
18+
Serial.println(i);
19+
address = i;
20+
Serial.println("Press 'c' to configure te new address");
21+
}
22+
}
23+
}
24+
25+
String pinstrapToName(uint8_t pinstrap) {
26+
switch (pinstrap) {
27+
case 0x3C:
28+
return "BUZZER";
29+
case 0x7C:
30+
return "BUTTONS";
31+
case 0x76:
32+
case 0x74:
33+
return "ENCODER";
34+
case 0x6C:
35+
return "SMARTLEDS";
36+
}
37+
return "UNKNOWN";
38+
}
39+
40+
void loop() {
41+
// put your main code here, to run repeatedly:
42+
if (Serial.available()) {
43+
if (Serial.read() == 'c') {
44+
Serial.print("Assigning new address to ");
45+
Serial.println(address);
46+
uint8_t data[40] = { 'C', 'F', new_address * 2 };
47+
Wire1.beginTransmission(address);
48+
Wire1.write(data, 8);
49+
Wire1.endTransmission();
50+
delay(1000);
51+
Wire1.requestFrom(new_address, 1);
52+
Serial.println("Device type " + pinstrapToName(Wire1.read()) + " at new address " + String(new_address));
53+
}
54+
}
55+
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#include "Modulino.h"
2+
3+
Buttons buttons;
4+
Tone buzzer;
5+
LEDS leds;
6+
Encoder encoder;
7+
Distance distance;
8+
9+
void setup() {
10+
11+
Serial.begin(115200);
12+
Modulino.begin();
13+
14+
color.begin();
15+
distance.begin();
16+
17+
buttons.begin();
18+
encoder.begin();
19+
buzzer.begin();
20+
leds.begin();
21+
22+
imu.begin();
23+
imu.setContinuousMode();
24+
barometer.begin();
25+
//humidity.begin();
26+
}
27+
28+
int skip = 0;
29+
int pitch = 0;
30+
bool a = false;
31+
bool b = false;
32+
bool c = false;
33+
34+
void loop() {
35+
36+
float x;
37+
float y;
38+
float z;
39+
40+
if (encoder.pressed()) {
41+
skip = (skip + 1) % 5;
42+
}
43+
44+
pitch = encoder.get() + distance.get();
45+
46+
if (Serial.available() && Serial.read() == 's') {
47+
imu.readAcceleration(x, y, z);
48+
Serial.print("IMU: x ");
49+
Serial.print(x, 3);
50+
Serial.print("\ty ");
51+
Serial.print(y, 3);
52+
Serial.print("\tz ");
53+
Serial.println(z, 3);
54+
55+
Serial.print("Pressure: " + String(barometer.readPressure()));
56+
Serial.println("\tTemperature: " + String(barometer.readTemperature()));
57+
}
58+
59+
//Serial.print("Humidity: " + String(humidity.readHumidity()));
60+
//Serial.println("\tTemperature: " + String(humidity.readTemperature()));
61+
62+
if (color.available()) {
63+
int r;
64+
int g;
65+
int b;
66+
color.read(r, g, b);
67+
leds.set(4 + skip, r, g, b, 255);
68+
leds.show();
69+
}
70+
71+
if (buttons.get(a, b, c)) {
72+
if (a) {
73+
leds.set(1 + skip, RED, 15);
74+
buzzer.tone(440 + pitch, 1000);
75+
} else {
76+
leds.clear(1 + skip);
77+
}
78+
if (b) {
79+
leds.set(2 + skip, BLUE, 15);
80+
buzzer.tone(880 + pitch, 1000);
81+
} else {
82+
leds.clear(2 + skip);
83+
}
84+
if (c) {
85+
leds.set(3 + skip, GREEN, 15);
86+
buzzer.tone(1240 + pitch, 1000);
87+
} else {
88+
leds.clear(3 + skip);
89+
}
90+
leds.show();
91+
}
92+
}

0 commit comments

Comments
 (0)