first commit
This commit is contained in:
260
Radio433_2_BMP_Narco_NoSerial/Radio433_2_BMP_Narco_NoSerial.ino
Executable file
260
Radio433_2_BMP_Narco_NoSerial/Radio433_2_BMP_Narco_NoSerial.ino
Executable file
@@ -0,0 +1,260 @@
|
||||
/*
|
||||
* 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 <avr/sleep.h>
|
||||
#include <avr/power.h>
|
||||
|
||||
#define LED_PIN (13)
|
||||
|
||||
volatile int f_timer=0;
|
||||
volatile int f_blc=0;
|
||||
|
||||
|
||||
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 = 2;
|
||||
const int EchoPin = 3;
|
||||
|
||||
// ################# Barometre ####
|
||||
Adafruit_BMP085 bmp;
|
||||
// #####################
|
||||
|
||||
const unsigned long TIME = 512;
|
||||
const unsigned long TWOTIME = TIME*2;
|
||||
|
||||
|
||||
// ====SLEEP=====================================================
|
||||
/***************************************************
|
||||
* Name: ISR(TIMER1_OVF_vect)
|
||||
*
|
||||
* Returns: Nothing.
|
||||
*
|
||||
* Parameters: None.
|
||||
*
|
||||
* Description: Timer1 Overflow interrupt.
|
||||
*
|
||||
***************************************************/
|
||||
ISR(TIMER1_OVF_vect)
|
||||
{
|
||||
f_blc++;
|
||||
/* set the flag. */
|
||||
if(f_timer == 0 & f_blc >= 4)
|
||||
{
|
||||
f_timer = 1;
|
||||
f_blc = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/***************************************************
|
||||
* Name: enterSleep
|
||||
*
|
||||
* Returns: Nothing.
|
||||
*
|
||||
* Parameters: None.
|
||||
*
|
||||
* Description: Enters the arduino into sleep mode.
|
||||
*
|
||||
***************************************************/
|
||||
void enterSleep(void)
|
||||
{
|
||||
set_sleep_mode(SLEEP_MODE_IDLE);
|
||||
|
||||
sleep_enable();
|
||||
|
||||
|
||||
/* Disable all of the unused peripherals. This will reduce power
|
||||
* consumption further and, more importantly, some of these
|
||||
* peripherals may generate interrupts that will wake our Arduino from
|
||||
* sleep!
|
||||
*/
|
||||
power_adc_disable();
|
||||
power_spi_disable();
|
||||
power_timer0_disable();
|
||||
power_timer2_disable();
|
||||
power_twi_disable();
|
||||
|
||||
/* Now enter sleep mode. */
|
||||
sleep_mode();
|
||||
|
||||
/* The program will continue from here after the timer timeout*/
|
||||
sleep_disable(); /* First thing to do is disable sleep. */
|
||||
|
||||
Serial.println("Wake Up");
|
||||
/* Re-enable the peripherals. */
|
||||
power_all_enable();
|
||||
}
|
||||
|
||||
// =============================================================
|
||||
/******************************************************************/
|
||||
|
||||
void setup() {
|
||||
|
||||
mySwitch.enableTransmit(TRANSMITTER_PIN);
|
||||
pinMode(TrigPin, OUTPUT);
|
||||
pinMode(EchoPin, INPUT);
|
||||
Serial.begin(115200);
|
||||
|
||||
// BMP
|
||||
if (!bmp.begin()) {
|
||||
while (1) {}
|
||||
}
|
||||
|
||||
// Sleep
|
||||
/* Don't forget to configure the pin! */
|
||||
pinMode(LED_PIN, OUTPUT);
|
||||
|
||||
/*** Configure the timer.***/
|
||||
|
||||
/* Normal timer operation.*/
|
||||
TCCR1A = 0x00;
|
||||
|
||||
/* Clear the timer counter register.
|
||||
* You can pre-load this register with a value in order to
|
||||
* reduce the timeout period, say if you wanted to wake up
|
||||
* ever 4.0 seconds exactly.
|
||||
*/
|
||||
TCNT1=0x0000;
|
||||
|
||||
/* Configure the prescaler for 1:1024, giving us a
|
||||
* timeout of 4.09 seconds.
|
||||
*/
|
||||
TCCR1B = 0x05;
|
||||
|
||||
/* Enable the timer overlow interrupt. */
|
||||
TIMSK1=0x01;
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
// en premier pour la température
|
||||
if(f_timer==1)
|
||||
{
|
||||
f_timer = 0;
|
||||
/* Toggle the LED */
|
||||
digitalWrite(LED_PIN, HIGH);
|
||||
barometre();
|
||||
|
||||
readSensors();
|
||||
|
||||
//readPresence();
|
||||
|
||||
sendAll();
|
||||
digitalWrite(LED_PIN, LOW);
|
||||
|
||||
/* Re-enter sleep mode. */
|
||||
enterSleep();
|
||||
}
|
||||
|
||||
|
||||
// delay(45000);
|
||||
|
||||
}
|
||||
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);
|
||||
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(100);
|
||||
mySwitch.send(value, 32);
|
||||
delay(100);
|
||||
|
||||
Serial.print(id);
|
||||
Serial.print("=");
|
||||
Serial.println(value);
|
||||
// mySwitch.switchOn(buf,buf2);
|
||||
// mySwitch.switchOn(id, value);
|
||||
// delay(1000);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user