diff --git a/sodaq_one/ledcolours.ino b/sodaq_one/ledcolours.ino index 6a2f53d..8bd851e 100644 --- a/sodaq_one/ledcolours.ino +++ b/sodaq_one/ledcolours.ino @@ -67,3 +67,10 @@ void setupLED() { pinMode(LED_GREEN, OUTPUT); pinMode(LED_BLUE, OUTPUT); } + +void signal_loop_start() +{ + blink(30); delay(50); + blink(30); delay(50); + blink(30); delay(50); +} diff --git a/sodaq_one/main_much_collected.ino b/sodaq_one/main_much_collected.ino new file mode 100644 index 0000000..7e85c40 --- /dev/null +++ b/sodaq_one/main_much_collected.ino @@ -0,0 +1,146 @@ +#include +#include +#include +#include +#include "nsarduino.h" +#include "internal.h" + +#define debugSerial SerialUSB + +int cnt; + +void setup_much_collected() { + while ((!SerialUSB) && (millis() < 10000)){ + // Wait 10 seconds for the Serial Monitor + } + + loraSetup(); + + /* Enable the pins 2/3, 6/7 and 8/9 */ + pinMode(11, OUTPUT); + digitalWrite(11, HIGH); + + setupLED(); + + // setupWater(WATER_SENSOR_PIN); + setupBuzzer(BUZZER_PIN); + + // gpsSetup(); + + // setupBuzzer(); + + // setupCompass(); +// setupSunLight(); + + buzz(BUZZER_PIN, 100); + cnt = 0; +} + +String tmps; +float tmp; + +#define SLEEPTIME 10000 +#define LOUDNESS_AVG 3 + +int loudnesses[LOUDNESS_AVG]; + +void loop_much_collected() { + signal_loop_start(); + + debugSerial.println("Deveui = " + String(LORADEV) + " => " + String(LORA_ADDR)); + + /* if(hasWater(WATER_SENSOR_PIN)) { */ + /* debugSerial.println("Having water"); */ + /* loraSend(getWater(WATER_SENSOR_PIN)); */ + /* buzz(BUZZER_PIN, 5000); */ + /* } else { */ + /* loraSend(getWater(WATER_SENSOR_PIN)); */ + /* debugSerial.println("it's dry"); */ + /* } */ + +// loraSend(getSunLight()); + // loraSend(getTempHumidHDC1000()); + // loraSend(getCompass()); + + /* Tracker code */ + /* if((tmps = gpsGetPostion(120)) != "") { */ + /* loraSend(tmps); */ + /* } */ + + sendIntAsString("battery=", getBattery()); + + /* Temp & loudness code */ + if(cnt < LOUDNESS_AVG) { + loudnesses[cnt] = readLoudness(LOUDNESS_PIN); + debugSerial.println("temploudness=" + String(loudnesses[cnt])); + cnt++; + } else { + tmp = 0; + for(cnt = 0; cnt < LOUDNESS_AVG; cnt++) { + tmp += loudnesses[cnt]; + } + tmp = tmp / (float) (cnt+1); + + sendFloatAsString("temperature=", getTemperature(TEMP_PIN)); + sendFloatAsString("loudness=", tmp); + + + /* audio representation of temperature */ + tmp = getTemperature(TEMP_PIN); + + if(tmp < 0) { + buzz(BUZZER_PIN, 50); + } + + if(tmp > 0 && tmp <= 20) { + buzz(BUZZER_PIN, 100); + delay(50); + buzz(BUZZER_PIN, 100); + } + + if(tmp > 20 && tmp <= 30) { + buzz(BUZZER_PIN, 100); + delay(50); + buzz(BUZZER_PIN, 100); + delay(50); + buzz(BUZZER_PIN, 100); + } + + if(tmp > 30 && tmp <= 40) { + buzz(BUZZER_PIN, 100); + delay(50); + buzz(BUZZER_PIN, 100); + delay(50); + buzz(BUZZER_PIN, 100); + delay(50); + buzz(BUZZER_PIN, 100); + } + + if(tmp > 40) { + buzz(BUZZER_PIN, 3000); + delay(50); + } + + + + cnt = 0; + } + + delay(SLEEPTIME); +} + + +/* Node = 2 +48 +48 +48 +52 +65 +51 +48 +66 + +hex: 3030303441333042 +*/ + +/* temp / humidity code (not functional) diff --git a/sodaq_one/main_temperature_alarm.ino b/sodaq_one/main_temperature_alarm.ino new file mode 100644 index 0000000..3d8823b --- /dev/null +++ b/sodaq_one/main_temperature_alarm.ino @@ -0,0 +1,150 @@ +#include +#include +#include +#include +#include "nsarduino.h" +#include "internal.h" + +#define debugSerial SerialUSB + +#define TEMP_PIN 2 +#define LOUDNESS_PIN 0 +#define BUZZER_PIN 6 + +int cnt; + +void setup_temperature_alarm() { + while ((!SerialUSB) && (millis() < 10000)){ + // Wait 10 seconds for the Serial Monitor + } + + loraSetup(); + + /* Enable the pins 2/3, 6/7 and 8/9 */ + pinMode(11, OUTPUT); + digitalWrite(11, HIGH); + + setupLED(); + + // setupWater(WATER_SENSOR_PIN); + setupBuzzer(BUZZER_PIN); + + // gpsSetup(); + + // setupBuzzer(); + + // setupCompass(); +// setupSunLight(); + + buzz(BUZZER_PIN, 100); + cnt = 0; +} + +String tmps; +float tmp; + +#define SLEEPTIME 10000 +#define LOUDNESS_AVG 3 + +int loudnesses[LOUDNESS_AVG]; + +void loop() { + signal_loop_start(); + + debugSerial.println("Deveui = " + String(LORADEV) + " => " + String(LORA_ADDR)); + + /* if(hasWater(WATER_SENSOR_PIN)) { */ + /* debugSerial.println("Having water"); */ + /* loraSend(getWater(WATER_SENSOR_PIN)); */ + /* buzz(BUZZER_PIN, 5000); */ + /* } else { */ + /* loraSend(getWater(WATER_SENSOR_PIN)); */ + /* debugSerial.println("it's dry"); */ + /* } */ + +// loraSend(getSunLight()); + // loraSend(getTempHumidHDC1000()); + // loraSend(getCompass()); + + /* Tracker code */ + /* if((tmps = gpsGetPostion(120)) != "") { */ + /* loraSend(tmps); */ + /* } */ + + sendIntAsString("battery=", getBattery()); + + /* Temp & loudness code */ + if(cnt < LOUDNESS_AVG) { + loudnesses[cnt] = readLoudness(LOUDNESS_PIN); + debugSerial.println("temploudness=" + String(loudnesses[cnt])); + cnt++; + } else { + tmp = 0; + for(cnt = 0; cnt < LOUDNESS_AVG; cnt++) { + tmp += loudnesses[cnt]; + } + tmp = tmp / (float) (cnt+1); + + sendFloatAsString("temperature=", getTemperature(TEMP_PIN)); + sendFloatAsString("loudness=", tmp); + + + /* audio representation of temperature */ + tmp = getTemperature(TEMP_PIN); + + if(tmp < 0) { + buzz(BUZZER_PIN, 50); + } + + if(tmp > 0 && tmp <= 20) { + buzz(BUZZER_PIN, 100); + delay(50); + buzz(BUZZER_PIN, 100); + } + + if(tmp > 20 && tmp <= 30) { + buzz(BUZZER_PIN, 100); + delay(50); + buzz(BUZZER_PIN, 100); + delay(50); + buzz(BUZZER_PIN, 100); + } + + if(tmp > 30 && tmp <= 40) { + buzz(BUZZER_PIN, 100); + delay(50); + buzz(BUZZER_PIN, 100); + delay(50); + buzz(BUZZER_PIN, 100); + delay(50); + buzz(BUZZER_PIN, 100); + } + + if(tmp > 40) { + buzz(BUZZER_PIN, 3000); + delay(50); + } + + + + cnt = 0; + } + + delay(SLEEPTIME); +} + + +/* Node = 2 +48 +48 +48 +52 +65 +51 +48 +66 + +hex: 3030303441333042 +*/ + +/* temp / humidity code (not functional) diff --git a/sodaq_one/lora.ino b/sodaq_one/ns_lora.ino similarity index 100% rename from sodaq_one/lora.ino rename to sodaq_one/ns_lora.ino diff --git a/sodaq_one/loudness.ino b/sodaq_one/ns_loudness.ino similarity index 100% rename from sodaq_one/loudness.ino rename to sodaq_one/ns_loudness.ino diff --git a/sodaq_one/temperature.ino b/sodaq_one/ns_temperature.ino similarity index 100% rename from sodaq_one/temperature.ino rename to sodaq_one/ns_temperature.ino diff --git a/sodaq_one/nsarduino.h b/sodaq_one/nsarduino.h index 98ea6fe..fd83969 100644 --- a/sodaq_one/nsarduino.h +++ b/sodaq_one/nsarduino.h @@ -7,6 +7,7 @@ int getBattery(); void blink(int length); void led_on(); void led_off(); +void signal_loop_start(); void setupBuzzer(int pin); diff --git a/sodaq_one/sodaq_one.ino b/sodaq_one/sodaq_one.ino index 335422a..b6e1858 100644 --- a/sodaq_one/sodaq_one.ino +++ b/sodaq_one/sodaq_one.ino @@ -26,40 +26,20 @@ void setup() { // Wait 10 seconds for the Serial Monitor } - loraSetup(); - - /* Enable the pins 2/3, 6/7 and 8/9 */ - pinMode(11, OUTPUT); - digitalWrite(11, HIGH); - - setupLED(); - - // setupWater(WATER_SENSOR_PIN); - setupBuzzer(BUZZER_PIN); - - // gpsSetup(); - - // setupBuzzer(); - - // setupCompass(); -// setupSunLight(); - - buzz(BUZZER_PIN, 100); - cnt = 0; } String tmps; float tmp; #define SLEEPTIME 10000 +#define LOUDNESS_AVG 3 -#define LOUDNESS_AVG 60 int loudnesses[LOUDNESS_AVG]; void loop() { signal_loop_start(); - debugSerial.println("Deveui=" + String(LORADEV) + " => " + String(LORA_ADDR)); + debugSerial.println("Deveui = " + String(LORADEV) + " => " + String(LORA_ADDR)); /* if(hasWater(WATER_SENSOR_PIN)) { */ /* debugSerial.println("Having water"); */ @@ -74,13 +54,13 @@ void loop() { // loraSend(getTempHumidHDC1000()); // loraSend(getCompass()); - sendIntAsString("battery=", getBattery()); - /* Tracker code */ /* if((tmps = gpsGetPostion(120)) != "") { */ /* loraSend(tmps); */ /* } */ + sendIntAsString("battery=", getBattery()); + /* Temp & loudness code */ if(cnt < LOUDNESS_AVG) { loudnesses[cnt] = readLoudness(LOUDNESS_PIN); @@ -93,8 +73,48 @@ void loop() { } tmp = tmp / (float) (cnt+1); - sendFloatAsString("loudness=", tmp); sendFloatAsString("temperature=", getTemperature(TEMP_PIN)); + sendFloatAsString("loudness=", tmp); + + + /* audio representation of temperature */ + tmp = getTemperature(TEMP_PIN); + + if(tmp < 0) { + buzz(BUZZER_PIN, 50); + } + + if(tmp > 0 && tmp <= 20) { + buzz(BUZZER_PIN, 100); + delay(50); + buzz(BUZZER_PIN, 100); + } + + if(tmp > 20 && tmp <= 30) { + buzz(BUZZER_PIN, 100); + delay(50); + buzz(BUZZER_PIN, 100); + delay(50); + buzz(BUZZER_PIN, 100); + } + + if(tmp > 30 && tmp <= 40) { + buzz(BUZZER_PIN, 100); + delay(50); + buzz(BUZZER_PIN, 100); + delay(50); + buzz(BUZZER_PIN, 100); + delay(50); + buzz(BUZZER_PIN, 100); + } + + if(tmp > 40) { + buzz(BUZZER_PIN, 3000); + delay(50); + } + + + cnt = 0; }