Skip to content

Commit 1e9471c

Browse files
authored
Merge pull request #6 from marcmerlin/Combined_Demo
New combined demo showing most of the features together.
2 parents 3778fc1 + a135ba8 commit 1e9471c

File tree

1 file changed

+102
-0
lines changed

1 file changed

+102
-0
lines changed
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
// 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
5+
6+
#include "Arduino_SensorKit.h"
7+
8+
#define BUZZER 5
9+
#define BUTTON 4
10+
#define LED 6
11+
#define POT A0
12+
#define MIC A2
13+
#define LIGHT A3
14+
15+
int pot_value;
16+
bool button_state;
17+
int mic_value;
18+
int light_value;
19+
20+
void setup() {
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+
31+
Environment.begin();
32+
33+
Oled.begin();
34+
Oled.setFlipMode(true);
35+
36+
Accelerometer.begin();
37+
Pressure.begin();
38+
}
39+
40+
void loop() {
41+
Oled.setFont(u8x8_font_amstrad_cpc_extended_r);
42+
43+
//cursor values are in characters, not pixels
44+
Oled.setCursor(0, 4);
45+
46+
// If accelerometer and altimeter are queried too close to one another
47+
// this causes a hang, so we read this first.
48+
Oled.print("x:");
49+
Oled.print(Accelerometer.readX());
50+
Oled.print(" y:");
51+
Oled.print(Accelerometer.readY());
52+
Oled.setCursor(0, 5);
53+
Oled.print("z:");
54+
Oled.print(Accelerometer.readZ());
55+
Oled.print(" T:");
56+
Oled.print(Environment.readTemperature());
57+
Oled.print("C");
58+
59+
Oled.setCursor(0, 0);
60+
Oled.print("But:");
61+
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);
69+
tone(BUZZER, pot_value);
70+
} else {
71+
digitalWrite(LED, LOW);
72+
noTone(BUZZER);
73+
}
74+
75+
Oled.setCursor(0, 1);
76+
Oled.print("BuzPot: ");
77+
Oled.print(pot_value);
78+
Oled.print("Hz ");
79+
80+
mic_value = analogRead(MIC);
81+
Oled.setCursor(0, 2);
82+
Oled.print("Mic: ");
83+
Oled.print(mic_value);
84+
Oled.print(" ");
85+
86+
light_value = analogRead(LIGHT);
87+
Oled.setCursor(0, 3);
88+
Oled.print("Light: ");
89+
Oled.print(light_value);
90+
Oled.print(" ");
91+
92+
Oled.setCursor(0, 6);
93+
Oled.print("Hum: ");
94+
Oled.print(Environment.readHumidity());
95+
Oled.print("%");
96+
97+
Oled.setCursor(0, 7);
98+
Oled.print("Alt:");
99+
Oled.print(Pressure.readAltitude());
100+
101+
delay(100);
102+
}

0 commit comments

Comments
 (0)