Skip to content

Commit cac3172

Browse files
committed
New combined demo showing most non I2C input sensors.
It'd be great to query I2C too, but those sensors unfortunately are not setup to use a different I2C address and conflict with one another unless you put some solder bridges to change the address
1 parent 859bdf0 commit cac3172

File tree

1 file changed

+96
-0
lines changed

1 file changed

+96
-0
lines changed
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
// Combined Demo by Marc MERLIN <marc_soft@merlins.org>
2+
3+
#include "Arduino_SensorKit.h"
4+
5+
uint8_t button = 4;
6+
uint8_t led = 6;
7+
uint8_t pot = A0;
8+
uint8_t mic = A2;
9+
uint8_t light = A3;
10+
11+
void setup() {
12+
#if 0
13+
// Accelerometer and Oled both share the same I2C address
14+
// both cannot be used at the same time, unless you solder
15+
// across the I2C address solder pads on the Oled module
16+
Accelerometer.begin();
17+
// Same problem with pressure sensor
18+
Pressure.begin();
19+
#endif
20+
21+
pinMode(mic , INPUT);
22+
pinMode(light , INPUT);
23+
24+
pinMode(button , INPUT);
25+
pinMode(led, OUTPUT);
26+
digitalWrite(led, LOW);
27+
28+
Environment.begin();
29+
30+
Oled.begin();
31+
Oled.setFlipMode(true);
32+
}
33+
34+
void loop() {
35+
36+
Oled.setFont(u8x8_font_amstrad_cpc_extended_r);
37+
38+
#if 0
39+
Oled.setCursor(0, 0);
40+
Oled.print("x:");
41+
Oled.print(Accelerometer.readX());
42+
Oled.print(" ");
43+
Oled.print("y:");
44+
Oled.print(Accelerometer.readY());
45+
Oled.print(" ");
46+
Oled.print("z:");
47+
Oled.print(Accelerometer.readZ());
48+
// Similar problem with pressure sensor
49+
Oled.print(Pressure.readAltitude());
50+
#endif
51+
52+
Oled.setCursor(0, 0);
53+
Oled.print("But:");
54+
if (digitalRead(button)) {
55+
digitalWrite(led, HIGH);
56+
Oled.print("1");
57+
} else {
58+
digitalWrite(led, LOW);
59+
Oled.print("0");
60+
}
61+
62+
// https://github.com/olikraus/u8g2/wiki/u8x8reference#print
63+
// looks like we need an offset of 9 for a font of 8
64+
// if the offset is wrong, the text gets displayed on
65+
// the wrong line
66+
uint16_t pot_value = analogRead(pot);
67+
Oled.setCursor(0, 9);
68+
Oled.print("Pot: ");
69+
Oled.print(pot_value);
70+
Oled.print(" ");
71+
72+
uint16_t mic_value = analogRead(mic);
73+
Oled.setCursor(0, 18);
74+
Oled.print("Mic: ");
75+
Oled.print(mic_value);
76+
Oled.print(" ");
77+
78+
uint16_t light_value = analogRead(light);
79+
Oled.setCursor(0, 27);
80+
Oled.print("Light: ");
81+
Oled.print(light_value);
82+
Oled.print(" ");
83+
84+
Oled.setCursor(0, 45);
85+
Oled.print("Temp:");
86+
Oled.print(Environment.readTemperature());
87+
Oled.print("C");
88+
89+
Oled.setCursor(0, 54);
90+
Oled.print("Hum: ");
91+
Oled.print(Environment.readHumidity());
92+
Oled.print("%");
93+
94+
Oled.refreshDisplay();
95+
delay(100);
96+
}

0 commit comments

Comments
 (0)