Skip to content

Commit cb7fbd7

Browse files
committed
Added I2C scanner for debug + fixed diplay offset + add tone.
When pushing the button, output a tone.
1 parent 5e1fccb commit cb7fbd7

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

examples/Combined_Demo/Combined_Demo.ino

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Combined Demo by Marc MERLIN <marc_soft@merlins.org>
22

33
#include "Arduino_SensorKit.h"
4+
#define BUZZER 5
45

56
uint8_t button = 4;
67
uint8_t led = 6;
@@ -75,6 +76,8 @@ void setup() {
7576
// Enabling any of those 2 stops the OLED from working
7677
//Accelerometer.begin();
7778
//Pressure.begin();
79+
80+
pinMode(BUZZER, OUTPUT);
7881
}
7982

8083
void loop() {
@@ -95,48 +98,47 @@ void loop() {
9598
Oled.print(Pressure.readAltitude());
9699
#endif
97100

101+
// when using u8g8 instead of u8g2, cursor values
102+
// are in characters, not pixels
98103
Oled.setCursor(0, 0);
99104
Oled.print("But:");
100105
if (digitalRead(button)) {
101106
digitalWrite(led, HIGH);
102107
Oled.print("1");
108+
tone(BUZZER, 440);
103109
} else {
104110
digitalWrite(led, LOW);
105111
Oled.print("0");
112+
noTone(BUZZER);
106113
}
107114

108-
// https://github.com/olikraus/u8g2/wiki/u8x8reference#print
109-
// looks like we need an offset of 9 for a font of 8
110-
// if the offset is wrong, the text gets displayed on
111-
// the wrong line
112115
uint16_t pot_value = analogRead(pot);
113-
Oled.setCursor(0, 9);
116+
Oled.setCursor(0, 1);
114117
Oled.print("Pot: ");
115118
Oled.print(pot_value);
116119
Oled.print(" ");
117120

118121
uint16_t mic_value = analogRead(mic);
119-
Oled.setCursor(0, 18);
122+
Oled.setCursor(0, 2);
120123
Oled.print("Mic: ");
121124
Oled.print(mic_value);
122125
Oled.print(" ");
123126

124127
uint16_t light_value = analogRead(light);
125-
Oled.setCursor(0, 27);
128+
Oled.setCursor(0, 3);
126129
Oled.print("Light: ");
127130
Oled.print(light_value);
128131
Oled.print(" ");
129132

130-
Oled.setCursor(0, 45);
133+
Oled.setCursor(0, 6);
131134
Oled.print("Temp:");
132135
Oled.print(Environment.readTemperature());
133136
Oled.print("C");
134137

135-
Oled.setCursor(0, 54);
138+
Oled.setCursor(0, 7);
136139
Oled.print("Hum: ");
137140
Oled.print(Environment.readHumidity());
138141
Oled.print("%");
139142

140-
Oled.refreshDisplay();
141143
delay(100);
142144
}

0 commit comments

Comments
 (0)