Skip to content

Commit a135ba8

Browse files
authored
Update Combined_Demo.ino
1 parent 0c4797d commit a135ba8

File tree

1 file changed

+37
-77
lines changed

1 file changed

+37
-77
lines changed

examples/Combined_Demo/Combined_Demo.ino

Lines changed: 37 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,90 +1,48 @@
11
// Combined Demo by Marc MERLIN <marc_soft@merlins.org>
2+
// Reviewed by Pablo Marquínez <p.marquinez@arduino.cc>
3+
// This demo use all the devices from the Arduino SensorKit
4+
// Showing the values on the Display
25

36
#include "Arduino_SensorKit.h"
7+
48
#define BUZZER 5
9+
#define BUTTON 4
10+
#define LED 6
11+
#define POT A0
12+
#define MIC A2
13+
#define LIGHT A3
514

6-
uint8_t button = 4;
7-
uint8_t led = 6;
8-
uint8_t pot = A0;
9-
uint8_t mic = A2;
10-
uint8_t light = A3;
11-
12-
// From https://playground.arduino.cc/Main/I2cScanner/
13-
// learn more about I2C here
14-
// https://www.seeedstudio.com/blog/2019/09/25/uart-vs-i2c-vs-spi-communication-protocols-and-uses/
15-
// Scanner from https://github.com/RobTillaart/Arduino/blob/master/sketches/MultiSpeedI2CScanner/MultiSpeedI2CScanner.ino
16-
// 30038 25 0x19 V V V V V V V V
17-
// 30133 60 0x3C V V V V V V V V
18-
// 30296 119 0x77 V V V V V V V V
19-
void i2c_scan() {
20-
uint8_t error, address, nDevices;
21-
22-
Wire.begin();
23-
Serial.println("Scanning...");
24-
25-
nDevices = 0;
26-
for(address = 1; address < 127; address++ )
27-
{
28-
// The i2c_scanner uses the return value of
29-
// the Write.endTransmisstion to see if
30-
// a device did acknowledge to the address.
31-
Wire.beginTransmission(address);
32-
error = Wire.endTransmission();
33-
34-
if (error == 0)
35-
{
36-
Serial.print("I2C device found at address 0x");
37-
if (address<16)
38-
Serial.print("0");
39-
Serial.print(address,HEX);
40-
Serial.println(" !");
41-
42-
nDevices++;
43-
}
44-
else if (error==4)
45-
{
46-
Serial.print("Unknown error at address 0x");
47-
if (address<16)
48-
Serial.print("0");
49-
Serial.println(address,HEX);
50-
}
51-
}
52-
if (nDevices == 0)
53-
Serial.println("No I2C devices found\n");
54-
else
55-
Serial.println("done\n");
56-
}
15+
int pot_value;
16+
bool button_state;
17+
int mic_value;
18+
int light_value;
5719

5820
void setup() {
59-
Serial.begin(115200);
60-
// Running scan stops the OLED from working
61-
i2c_scan();
62-
63-
pinMode(mic , INPUT);
64-
pinMode(light , INPUT);
65-
66-
pinMode(button , INPUT);
67-
pinMode(led, OUTPUT);
68-
digitalWrite(led, LOW);
69-
21+
Serial.begin(9600);
22+
23+
pinMode(MIC , INPUT);
24+
pinMode(LIGHT , INPUT);
25+
pinMode(BUTTON , INPUT);
26+
27+
pinMode(LED, OUTPUT);
28+
digitalWrite(LED, LOW);
29+
pinMode(BUZZER, OUTPUT);
30+
7031
Environment.begin();
7132

7233
Oled.begin();
7334
Oled.setFlipMode(true);
7435

7536
Accelerometer.begin();
7637
Pressure.begin();
77-
78-
pinMode(BUZZER, OUTPUT);
7938
}
8039

8140
void loop() {
82-
8341
Oled.setFont(u8x8_font_amstrad_cpc_extended_r);
84-
85-
// when using u8g8 instead of u8g2, cursor values
86-
// are in characters, not pixels
42+
43+
//cursor values are in characters, not pixels
8744
Oled.setCursor(0, 4);
45+
8846
// If accelerometer and altimeter are queried too close to one another
8947
// this causes a hang, so we read this first.
9048
Oled.print("x:");
@@ -101,29 +59,31 @@ void loop() {
10159
Oled.setCursor(0, 0);
10260
Oled.print("But:");
10361

104-
uint16_t pot_value = analogRead(pot);
105-
if (digitalRead(button)) {
106-
digitalWrite(led, HIGH);
107-
Oled.print("1");
62+
pot_value = analogRead(POT);
63+
64+
button_state = digitalRead(BUTTON);
65+
Oled.print(button_state);
66+
67+
if (button_state == true) {
68+
digitalWrite(LED, HIGH);
10869
tone(BUZZER, pot_value);
10970
} else {
110-
digitalWrite(led, LOW);
111-
Oled.print("0");
71+
digitalWrite(LED, LOW);
11272
noTone(BUZZER);
11373
}
114-
74+
11575
Oled.setCursor(0, 1);
11676
Oled.print("BuzPot: ");
11777
Oled.print(pot_value);
11878
Oled.print("Hz ");
11979

120-
uint16_t mic_value = analogRead(mic);
80+
mic_value = analogRead(MIC);
12181
Oled.setCursor(0, 2);
12282
Oled.print("Mic: ");
12383
Oled.print(mic_value);
12484
Oled.print(" ");
12585

126-
uint16_t light_value = analogRead(light);
86+
light_value = analogRead(LIGHT);
12787
Oled.setCursor(0, 3);
12888
Oled.print("Light: ");
12989
Oled.print(light_value);

0 commit comments

Comments
 (0)