first commit
This commit is contained in:
201
Radio433_2_BMP_Narco_NoSerial_Sleep/Radio433_2_BMP_Narco_NoSerial_Sleep.ino
Executable file
201
Radio433_2_BMP_Narco_NoSerial_Sleep/Radio433_2_BMP_Narco_NoSerial_Sleep.ino
Executable file
@@ -0,0 +1,201 @@
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
#include <Wire.h>
|
||||
#include <Adafruit_BMP085.h>
|
||||
#include <RCSwitch.h>
|
||||
#include <Narcoleptic.h>
|
||||
|
||||
#define DEBUG TRUE
|
||||
#define SEND_MESSAGE_DELAY 1500 // Ne pas dépasser 32000 !! Delay in ms between each value's extraction
|
||||
#define SEND_433_PAUSE 160 // 16 multiple
|
||||
|
||||
const byte TRANSMITTER_PIN = 9;
|
||||
|
||||
// Init RCSwitch
|
||||
RCSwitch mySwitch = RCSwitch();
|
||||
|
||||
//
|
||||
float temperature = 0.0;
|
||||
float pressure = 0.0;
|
||||
float pression = 0.0;
|
||||
float presiune = 0.0;
|
||||
int sensorValue = 0;
|
||||
int sensorValue2 = 0;
|
||||
int sensorValue3 = 0;
|
||||
int distance = 0;
|
||||
|
||||
const int TrigPin = 4;
|
||||
const int EchoPin = 5;
|
||||
|
||||
|
||||
|
||||
// ################# Barometre ####
|
||||
Adafruit_BMP085 bmp;
|
||||
// #####################
|
||||
|
||||
const unsigned long TIME = 512;
|
||||
const unsigned long TWOTIME = TIME*2;
|
||||
|
||||
// --------
|
||||
// Wake up
|
||||
// --------
|
||||
int wakePin = 2; // pin used for waking up
|
||||
int sleepStatus = 0; // variable to store a request for sleep
|
||||
int count = 0; // counter
|
||||
|
||||
// ----------
|
||||
// Timer
|
||||
// ----------
|
||||
|
||||
void flash() {
|
||||
static boolean output = HIGH;
|
||||
|
||||
digitalWrite(13, output);
|
||||
|
||||
digitalWrite(wakePin, LOW);
|
||||
|
||||
output = !output;
|
||||
|
||||
|
||||
}
|
||||
|
||||
/******************************************************************/
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
|
||||
|
||||
mySwitch.enableTransmit(TRANSMITTER_PIN);
|
||||
pinMode(TrigPin, OUTPUT);
|
||||
pinMode(EchoPin, INPUT);
|
||||
|
||||
// BMP
|
||||
if (!bmp.begin()) {
|
||||
while (1) {}
|
||||
}
|
||||
|
||||
|
||||
//timer
|
||||
pinMode(13, OUTPUT);
|
||||
}
|
||||
|
||||
void loop () {
|
||||
Serial.println("Start loop");
|
||||
|
||||
// en premier pour la température
|
||||
barometre();
|
||||
|
||||
readSensors();
|
||||
|
||||
readPresence();
|
||||
|
||||
sendAll();
|
||||
|
||||
// if (irrecv.decode(&results)) {
|
||||
// // Serial.println(results.value, HEX);
|
||||
// irrecv.resume(); // Receive the next value
|
||||
// }
|
||||
|
||||
|
||||
Serial.println("End loop");
|
||||
|
||||
//delay(45000);
|
||||
Narcoleptic.delay(SEND_MESSAGE_DELAY);
|
||||
Narcoleptic.delay(SEND_MESSAGE_DELAY);
|
||||
}
|
||||
void sendAll() {
|
||||
|
||||
sendValues(1111, temperature * 100);
|
||||
|
||||
sendValues(2222, (int) (pression * 10));
|
||||
|
||||
sendValues(3333, (int) (pressure * 10));
|
||||
|
||||
// sendValues(4444, sensorValue);
|
||||
//
|
||||
// sendValues(5555, sensorValue2);
|
||||
//
|
||||
// sendValues(6666, (int) (sensorValue3 / 10.24));
|
||||
//
|
||||
// sendValues(7777, distance);
|
||||
|
||||
}
|
||||
|
||||
void barometre() {
|
||||
/* See Example: TypeA_WithDIPSwitches */
|
||||
// mySwitch.switchOn("00001", "10000");
|
||||
// delay(1000);
|
||||
if (bmp.begin()) {
|
||||
temperature = bmp.readTemperature();
|
||||
pressure= bmp.readPressure() / 100.0;
|
||||
pression = pressure / 101.325;
|
||||
pression = pression * 0.760 * 100;
|
||||
// http://en.wikipedia.org/wiki/Atmospheric_pressure#Mean_sea_level_pressure
|
||||
// Serial.print("Presiure la nivelul marii (calculata) = ");
|
||||
presiune = bmp.readSealevelPressure() / 101.325;
|
||||
presiune = presiune * 0.760;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void readPresence() {
|
||||
digitalWrite(TrigPin, LOW); //Low high and low level take a short time to TrigPin pulse
|
||||
delayMicroseconds(2);
|
||||
digitalWrite(TrigPin, HIGH);
|
||||
delayMicroseconds(10);
|
||||
digitalWrite(TrigPin, LOW);
|
||||
|
||||
float cm = pulseIn(EchoPin, HIGH) / 58.0; //Echo time conversion into cm
|
||||
cm = (int(cm * 100.0)) / 100.0; //Keep two decimal places
|
||||
|
||||
distance = cm * 100;
|
||||
|
||||
}
|
||||
|
||||
void readSensors() {
|
||||
// ##########################################"
|
||||
// Analogic read
|
||||
// ------------------------------------------
|
||||
// sensorValue = analogRead(A0);
|
||||
// sensorValue2 = analogRead(A1);
|
||||
// sensorValue3 = analogRead(A2);
|
||||
// int sensorValue4 = digitalRead(10);
|
||||
|
||||
//vol = (float)sensorValue / 1024 * 5.0;
|
||||
|
||||
// ##########################################
|
||||
|
||||
|
||||
}
|
||||
|
||||
void sendValues(int id, int value) {
|
||||
|
||||
mySwitch.send(id, 32);
|
||||
delay(10);
|
||||
mySwitch.send(value, 32);
|
||||
delay(10);
|
||||
|
||||
Serial.print("Id="); Serial.print(id);
|
||||
Serial.print(" value="); Serial.println(value);
|
||||
|
||||
Narcoleptic.delay(SEND_433_PAUSE);
|
||||
// mySwitch.switchOn(buf,buf2);
|
||||
// mySwitch.switchOn(id, value);
|
||||
// delay(1000);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user