Maeke code more generic

This commit is contained in:
Nico Schottelius 2016-11-12 20:01:48 +01:00
parent f82ff4fb88
commit 3662703836
3 changed files with 56 additions and 36 deletions

View file

@ -1,20 +1,20 @@
#include <Arduino.h>
void setupBuzzer()
void setupBuzzer(int pin)
{
pinMode(BUZZER_PIN, OUTPUT);
pinMode(pin, OUTPUT);
}
void buzzerOn() {
digitalWrite(BUZZER_PIN, HIGH);
void buzzerOn(int pin) {
digitalWrite(pin, HIGH);
}
void buzzerOff() {
digitalWrite(BUZZER_PIN, LOW);
void buzzerOff(int pin) {
digitalWrite(pin, LOW);
}
void buzz(int ms) {
buzzerOn();
void buzz(int pin, int ms) {
buzzerOn(pin);
delay(ms);
buzzerOff();
buzzerOff(pin);
}

View file

@ -49,7 +49,10 @@ void loraSetup()
void loraSend(String packet){
debugSerial.println("Trying to send: " + packet);
switch (LoRaBee.sendReqAck(1, (uint8_t*)packet.c_str(), packet.length(), 8))
/* with ack */
//switch (LoRaBee.sendReqAck(1, (uint8_t*)packet.c_str(), packet.length(), 8))
switch (LoRaBee.send(1, (uint8_t*)packet.c_str(), packet.length()) )
{
case NoError:
debugSerial.println("Successful transmission.");

View file

@ -12,6 +12,11 @@ void signal_loop_start()
blink(30); delay(50);
}
#define TEMP_PIN 2
#define LOUDNESS_PIN 0
#define BUZZER_PIN 2
#define WATER_SENSOR_PIN 6
int cnt;
void setup() {
@ -24,7 +29,11 @@ void setup() {
digitalWrite(11, HIGH);
setupLED();
// gpsSetup();
// setupWater(WATER_SENSOR_PIN);
// setupBuzzer(BUZZER_PIN);
gpsSetup();
// setupBuzzer();
@ -38,46 +47,54 @@ void setup() {
String tmps;
float tmp;
#define TEMP_PIN 2
#define LOUDNESS_PIN 0
#define BUZZER_PIN 6
#define SLEEPTIME 10000
#define LOUDNESS_AVG 6
#define LOUDNESS_AVG 60
int loudnesses[LOUDNESS_AVG];
void loop() {
signal_loop_start();
/* 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"); */
/* } */
// sendIntAsString("loudness=", readLoudness(LOUDNESS_PIN));
// loraSend(getSunLight());
// loraSend(getTempHumidHDC1000());
// loraSend(getCompass());
/* if((tmps = gpsGetPostion(120)) != "") { */
/* loraSend(tmps); */
if((tmps = gpsGetPostion(120)) != "") {
loraSend(tmps);
}
sendIntAsString("battery=", getBatteryVoltage());
/* 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); */
/* sendIntAsString("battery=", getBatteryVoltage()); */
/* sendFloatAsString("loudness=", tmp); */
/* sendFloatAsString("temperature=", getTemperature(TEMP_PIN)); */
/* cnt = 0; */
/* } */
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);
sendIntAsString("battery=", getBatteryVoltage());
sendFloatAsString("loudness=", tmp);
sendFloatAsString("temperature=", getTemperature(TEMP_PIN));
cnt = 0;
}
delay(SLEEPTIME);
}