#define BUTTON_PIN 6
+
+#define SOUND_PIN A2
+#define LIGHT_PIN A6
void setup(void) {
//u8x8.setBusClock(100000); // If you breakout other modules, please enable this line
Adafruit_BMP280::STANDBY_MS_500); /* Standby time. */
pinMode(BUTTON_PIN, OUTPUT);
+ pinMode(SOUND_PIN, INPUT);
+ pinMode(LIGHT_PIN, INPUT);
}
-unsigned long button_timeout;
+unsigned long t;
void loop(void) {
+ t = millis();
+
int oled_active = ! digitalRead(BUTTON_PIN);
u8x8.setPowerSave( oled_active );
u8x8.print(" ");
- u8x8.setCursor(0,9);
+ u8x8.setCursor(0,1 * 9);
u8x8.print("Humidity:");
u8x8.print(humi);
u8x8.print("%");
float pressure;
pressure = bmp.readPressure();
- u8x8.setCursor(0,18);
+ u8x8.setCursor(0,2 * 9);
u8x8.print( pressure );
Serial.print(",bmp_pressure=");
Serial.print(pressure);
+ unsigned long sumSquare;
+ for(int i=0; i++; i<1000) {
+ int sound = analogRead(SOUND_PIN);
+ sumSquare += sound * sound;
+ }
+ int rms_sound = sqrt(sumSquare / 1000);
+ Serial.print(",rms_sound=");
+ Serial.print(rms_sound);
+
+ int sound = analogRead(SOUND_PIN);
+ u8x8.setCursor(0,3 * 9);
+ u8x8.print( sound );
+ Serial.print(",sound=");
+ Serial.print(sound);
+
+ int light = analogRead(LIGHT_PIN);
+ u8x8.setCursor(0,3 * 9);
+ u8x8.print( light );
+ Serial.print(",light=");
+ Serial.print(light);
Serial.println();
u8x8.refreshDisplay();
- delay(1000);
+
+ // next loop in 1000ms from start
+ t = t + 1000 - millis();
+ delay(t);
}