first commit
This commit is contained in:
139
_433EmetteurSimple/_433EmetteurSimple.ino
Normal file
139
_433EmetteurSimple/_433EmetteurSimple.ino
Normal file
@@ -0,0 +1,139 @@
|
||||
#include <RCSwitch.h>
|
||||
#include <Narcoleptic.h>
|
||||
#include <Adafruit_BMP085.h>
|
||||
#include <Wire.h>
|
||||
|
||||
|
||||
#define SEND_MESSAGE_DELAY 10000 // Ne pas dépasser 32000 !! Delay in ms between each value's extraction
|
||||
#define SEND_433_PAUSE 160 // 16 multiple
|
||||
|
||||
const unsigned long activation = 111269;
|
||||
const unsigned long id=1969;
|
||||
const unsigned long id2=2069;
|
||||
const unsigned long id3=2169;
|
||||
const unsigned long id4=2269;
|
||||
const unsigned long desactivation = 962111;
|
||||
const unsigned int delai = 10;
|
||||
|
||||
const unsigned long TIME = 512;
|
||||
const unsigned long TWOTIME = TIME*2;
|
||||
|
||||
// ################# Barometre ####
|
||||
Adafruit_BMP085 bmp;
|
||||
// #####################
|
||||
|
||||
float temperature = 0.0;
|
||||
float pressure = 0.0;
|
||||
float pression = 0.0;
|
||||
float presiune = 0.0;
|
||||
|
||||
|
||||
RCSwitch mySwitch = RCSwitch();
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
mySwitch.enableTransmit(9);
|
||||
//mySwitch.setRepeatTransmit();
|
||||
}
|
||||
|
||||
// Prise Eléctrique
|
||||
//ON 1 1381719 1398103
|
||||
//ON 2 1394007
|
||||
//ON 3 1397079 1398103
|
||||
//
|
||||
//OFF 1 1381716
|
||||
//OFF 2 1398103
|
||||
//OFF 3 1397076
|
||||
|
||||
void loop() {
|
||||
long vcc = readVcc();
|
||||
//barometre();
|
||||
|
||||
Serial.println("Send");
|
||||
Serial.print(vcc);
|
||||
|
||||
myMessageSend(id,temperature * 100);
|
||||
myMessageSend(id2,pressure * 10);
|
||||
myMessageSend(id3,pression * 10);
|
||||
|
||||
// LUX
|
||||
// R=K*L^-gamma
|
||||
// R étant la résistance pour un niveau d'éclairement L.
|
||||
int lum = analogRead(1);
|
||||
myMessageSend(id4,(1000.0 * lum / 1024.0));
|
||||
|
||||
|
||||
// mySwitch.send(activation, 24);
|
||||
// (delai); //delayMicroseconds
|
||||
// mySwitch.send(id, 24); //"000000000001010100010001");
|
||||
// delay(delai);
|
||||
// mySwitch.send(vcc, 24); //"000000000001010100010001");
|
||||
// delay(delai);
|
||||
// mySwitch.send(desactivation, 24);
|
||||
// delay(delai);
|
||||
//delay(5000);
|
||||
// delayMicroseconds(TWOTIME*8);
|
||||
Narcoleptic.delay(SEND_MESSAGE_DELAY);
|
||||
Narcoleptic.delay(SEND_MESSAGE_DELAY);
|
||||
}
|
||||
void barometre() {
|
||||
/* See Example: TypeA_WithDIPSwitches */
|
||||
// mySwitch.switchOn("00001", "10000");
|
||||
// delay(1000);
|
||||
// BMP
|
||||
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(19) / 101.325;
|
||||
presiune = presiune * 0.760;
|
||||
|
||||
Serial.print("Temperature="); Serial.println(temperature);
|
||||
Serial.print("pressure="); Serial.println(pressure);
|
||||
Serial.print("pression="); Serial.println(pression);
|
||||
}
|
||||
}
|
||||
|
||||
void myMessageSend(long id, long value) {
|
||||
mySwitch.send(activation, 24);
|
||||
(delai); //delayMicroseconds
|
||||
mySwitch.send(id, 24); //"000000000001010100010001");
|
||||
delay(delai);
|
||||
mySwitch.send(value, 24); //"000000000001010100010001");
|
||||
delay(delai);
|
||||
mySwitch.send(desactivation, 24);
|
||||
delay(delai);
|
||||
//delay(5000);
|
||||
delayMicroseconds(TWOTIME*8);
|
||||
}
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
// Read current supply voltage
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
long readVcc() {
|
||||
bitClear(PRR, PRADC); ADCSRA |= bit(ADEN); // Enable the ADC
|
||||
long result;
|
||||
// Read 1.1V reference against Vcc
|
||||
#if defined (__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__)
|
||||
ADMUX = _BV(MUX5) | _BV(MUX0); // For ATtiny84
|
||||
#elif defined (__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)
|
||||
ADMUX = _BV(MUX3) | _BV(MUX2);
|
||||
#else
|
||||
ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1); // For ATmega328
|
||||
#endif
|
||||
// ADCSRB = 0;
|
||||
|
||||
delay(2); // Wait for Vref to settle
|
||||
ADCSRA |= _BV(ADSC); // Convert
|
||||
while (bit_is_set(ADCSRA,ADSC));
|
||||
result = ADCL;
|
||||
result |= ADCH<<8;
|
||||
result = 1126400L / result; // Back-calculate Vcc in mV
|
||||
// ADCSRA &= ~ bit(ADEN); bitSet(PRR, PRADC); // Disable the ADC to save power
|
||||
|
||||
// analogReference(DEFAULT);
|
||||
|
||||
return result; // Vcc in millivolts
|
||||
}
|
||||
Reference in New Issue
Block a user