Refactor - split out certain functionality

This commit is contained in:
Nico Schottelius 2017-02-20 09:45:16 +01:00
parent 4c28cc647f
commit dbe8c9faa1
8 changed files with 349 additions and 25 deletions

View file

@ -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);
}

View file

@ -0,0 +1,146 @@
#include <Arduino.h>
#include <Wire.h>
#include <math.h>
#include <Sodaq_UBlox_GPS.h>
#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)

View file

@ -0,0 +1,150 @@
#include <Arduino.h>
#include <Wire.h>
#include <math.h>
#include <Sodaq_UBlox_GPS.h>
#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)

View file

@ -7,6 +7,7 @@ int getBattery();
void blink(int length);
void led_on();
void led_off();
void signal_loop_start();
void setupBuzzer(int pin);

View file

@ -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;
}