2016-10-24 19:34:02 +00:00
|
|
|
#include <Arduino.h>
|
|
|
|
#include <Wire.h>
|
2016-10-27 16:14:29 +00:00
|
|
|
#include <math.h>
|
2016-10-24 19:34:02 +00:00
|
|
|
#include "nsarduino.h"
|
|
|
|
|
|
|
|
#define debugSerial SerialUSB
|
|
|
|
|
|
|
|
void signal_loop_start()
|
|
|
|
{
|
|
|
|
blink(30); delay(50);
|
|
|
|
blink(30); delay(50);
|
|
|
|
blink(30); delay(50);
|
|
|
|
}
|
|
|
|
|
2016-11-02 16:38:56 +00:00
|
|
|
int cnt;
|
2016-10-24 19:34:02 +00:00
|
|
|
|
|
|
|
void setup() {
|
|
|
|
while ((!SerialUSB) && (millis() < 10000)){
|
|
|
|
// Wait 10 seconds for the Serial Monitor
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Enable the pins 2/3, 6/7 and 8/9 */
|
|
|
|
pinMode(11, OUTPUT);
|
|
|
|
digitalWrite(11, HIGH);
|
|
|
|
|
|
|
|
setupLED();
|
2016-11-02 16:38:56 +00:00
|
|
|
// gpsSetup();
|
2016-10-27 16:14:29 +00:00
|
|
|
|
|
|
|
// setupBuzzer();
|
|
|
|
|
2016-11-02 16:38:56 +00:00
|
|
|
// setupCompass();
|
|
|
|
// setupSunLight();
|
2016-10-24 19:34:02 +00:00
|
|
|
loraSetup();
|
2016-10-27 16:14:29 +00:00
|
|
|
|
2016-11-02 16:38:56 +00:00
|
|
|
cnt = 0;
|
2016-10-24 19:34:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
String tmps;
|
2016-11-02 16:38:56 +00:00
|
|
|
float tmp;
|
2016-10-24 19:34:02 +00:00
|
|
|
|
2016-10-27 16:14:29 +00:00
|
|
|
#define TEMP_PIN 2
|
|
|
|
#define LOUDNESS_PIN 0
|
2016-11-03 07:08:08 +00:00
|
|
|
#define BUZZER_PIN 6
|
2016-10-27 16:14:29 +00:00
|
|
|
|
2016-11-02 16:38:56 +00:00
|
|
|
#define SLEEPTIME 10000
|
|
|
|
|
|
|
|
#define LOUDNESS_AVG 6
|
|
|
|
int loudnesses[LOUDNESS_AVG];
|
2016-10-27 16:14:29 +00:00
|
|
|
|
2016-10-24 19:34:02 +00:00
|
|
|
void loop() {
|
|
|
|
signal_loop_start();
|
|
|
|
|
2016-10-27 16:14:29 +00:00
|
|
|
|
2016-11-02 16:38:56 +00:00
|
|
|
// sendIntAsString("loudness=", readLoudness(LOUDNESS_PIN));
|
|
|
|
// loraSend(getSunLight());
|
|
|
|
// loraSend(getTempHumidHDC1000());
|
|
|
|
// loraSend(getCompass());
|
2016-10-24 19:34:02 +00:00
|
|
|
|
2016-11-02 16:38:56 +00:00
|
|
|
/* if((tmps = gpsGetPostion(120)) != "") { */
|
|
|
|
/* loraSend(tmps); */
|
|
|
|
/* } */
|
|
|
|
|
2016-11-03 07:08:08 +00:00
|
|
|
|
|
|
|
|
2016-11-02 16:38:56 +00:00
|
|
|
if(cnt < LOUDNESS_AVG) {
|
|
|
|
loudnesses[cnt] = readLoudness(LOUDNESS_PIN);
|
|
|
|
debugSerial.println("temploudness=" + String(loudnesses[cnt]));
|
|
|
|
cnt++;
|
2016-10-27 16:14:29 +00:00
|
|
|
} else {
|
2016-11-02 16:38:56 +00:00
|
|
|
tmp = 0;
|
|
|
|
for(cnt = 0; cnt < LOUDNESS_AVG; cnt++) {
|
|
|
|
tmp += loudnesses[cnt];
|
|
|
|
}
|
|
|
|
tmp = tmp / (float) (cnt+1);
|
|
|
|
|
2016-11-03 07:08:08 +00:00
|
|
|
sendIntAsString("battery=", getBatteryVoltage());
|
2016-11-02 16:38:56 +00:00
|
|
|
sendFloatAsString("loudness=", tmp);
|
2016-11-02 16:57:55 +00:00
|
|
|
sendFloatAsString("temperature=", getTemperature(TEMP_PIN));
|
2016-11-02 16:38:56 +00:00
|
|
|
cnt = 0;
|
2016-10-27 16:14:29 +00:00
|
|
|
}
|
2016-11-02 16:38:56 +00:00
|
|
|
delay(SLEEPTIME);
|
2016-10-24 19:34:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Node = 2
|
|
|
|
48
|
|
|
|
48
|
|
|
|
48
|
|
|
|
52
|
|
|
|
65
|
|
|
|
51
|
|
|
|
48
|
|
|
|
66
|
|
|
|
|
|
|
|
hex: 3030303441333042
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* temp / humidity code (not functional)
|
|
|
|
|
|
|
|
/* humid / temperature */
|
|
|
|
/*
|
|
|
|
|
|
|
|
|
2016-10-27 16:14:29 +00:00
|
|
|
*/
|