File tree Expand file tree Collapse file tree 1 file changed +12
-10
lines changed Expand file tree Collapse file tree 1 file changed +12
-10
lines changed Original file line number Diff line number Diff line change 1
1
// Combined Demo by Marc MERLIN <marc_soft@merlins.org>
2
2
3
3
#include " Arduino_SensorKit.h"
4
+ #define BUZZER 5
4
5
5
6
uint8_t button = 4 ;
6
7
uint8_t led = 6 ;
@@ -75,6 +76,8 @@ void setup() {
75
76
// Enabling any of those 2 stops the OLED from working
76
77
// Accelerometer.begin();
77
78
// Pressure.begin();
79
+
80
+ pinMode (BUZZER, OUTPUT);
78
81
}
79
82
80
83
void loop () {
@@ -95,48 +98,47 @@ void loop() {
95
98
Oled.print(Pressure.readAltitude());
96
99
#endif
97
100
101
+ // when using u8g8 instead of u8g2, cursor values
102
+ // are in characters, not pixels
98
103
Oled.setCursor (0 , 0 );
99
104
Oled.print (" But:" );
100
105
if (digitalRead (button)) {
101
106
digitalWrite (led, HIGH);
102
107
Oled.print (" 1" );
108
+ tone (BUZZER, 440 );
103
109
} else {
104
110
digitalWrite (led, LOW);
105
111
Oled.print (" 0" );
112
+ noTone (BUZZER);
106
113
}
107
114
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
112
115
uint16_t pot_value = analogRead (pot);
113
- Oled.setCursor (0 , 9 );
116
+ Oled.setCursor (0 , 1 );
114
117
Oled.print (" Pot: " );
115
118
Oled.print (pot_value);
116
119
Oled.print (" " );
117
120
118
121
uint16_t mic_value = analogRead (mic);
119
- Oled.setCursor (0 , 18 );
122
+ Oled.setCursor (0 , 2 );
120
123
Oled.print (" Mic: " );
121
124
Oled.print (mic_value);
122
125
Oled.print (" " );
123
126
124
127
uint16_t light_value = analogRead (light);
125
- Oled.setCursor (0 , 27 );
128
+ Oled.setCursor (0 , 3 );
126
129
Oled.print (" Light: " );
127
130
Oled.print (light_value);
128
131
Oled.print (" " );
129
132
130
- Oled.setCursor (0 , 45 );
133
+ Oled.setCursor (0 , 6 );
131
134
Oled.print (" Temp:" );
132
135
Oled.print (Environment.readTemperature ());
133
136
Oled.print (" C" );
134
137
135
- Oled.setCursor (0 , 54 );
138
+ Oled.setCursor (0 , 7 );
136
139
Oled.print (" Hum: " );
137
140
Oled.print (Environment.readHumidity ());
138
141
Oled.print (" %" );
139
142
140
- Oled.refreshDisplay ();
141
143
delay (100 );
142
144
}
You can’t perform that action at this time.
0 commit comments