alarm function
This commit is contained in:
parent
2ff0e5f79e
commit
58f24c54c1
|
@ -31,6 +31,7 @@
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <avr/sleep.h>
|
#include <avr/sleep.h>
|
||||||
#include <avr/wdt.h>
|
#include <avr/wdt.h>
|
||||||
|
#include <avr/interrupt.h>
|
||||||
#include <tinySPI.h>
|
#include <tinySPI.h>
|
||||||
|
|
||||||
|
|
||||||
|
@ -67,6 +68,10 @@
|
||||||
SHT21 sensor;
|
SHT21 sensor;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAS_ALARM
|
||||||
|
volatile boolean alarm = false;
|
||||||
|
#endif
|
||||||
|
|
||||||
// Global Variable to Track Deep Sleep
|
// Global Variable to Track Deep Sleep
|
||||||
uint16_t sleep_interval;
|
uint16_t sleep_interval;
|
||||||
|
|
||||||
|
@ -127,6 +132,12 @@ void sleep(uint16_t s)
|
||||||
s = s/8;
|
s = s/8;
|
||||||
sleep_interval = 0;
|
sleep_interval = 0;
|
||||||
while (sleep_interval < s) {
|
while (sleep_interval < s) {
|
||||||
|
// in case of alarm, break loop and transmit immediatly
|
||||||
|
#ifdef HAS_ALARM
|
||||||
|
if( alarm == true){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
|
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
|
||||||
sleep_mode();
|
sleep_mode();
|
||||||
}
|
}
|
||||||
|
@ -143,6 +154,16 @@ ISR(WATCHDOG_vect) {
|
||||||
WDTCSR = (1<<WDIE)|(1<<WDP3)|(1<<WDP0);
|
WDTCSR = (1<<WDIE)|(1<<WDP3)|(1<<WDP0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef HAS_ALARM
|
||||||
|
// innterrupt handler pin change
|
||||||
|
ISR(PCINT0_vect)
|
||||||
|
{
|
||||||
|
sleep_disable();
|
||||||
|
blink(1);
|
||||||
|
alarm = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
// Get Battery Voltage
|
// Get Battery Voltage
|
||||||
int32_t readVcc() {
|
int32_t readVcc() {
|
||||||
bitClear(PRR, PRADC);
|
bitClear(PRR, PRADC);
|
||||||
|
@ -221,6 +242,14 @@ void setup()
|
||||||
radio.setPowerLevel(RFM69_TXPOWER);
|
radio.setPowerLevel(RFM69_TXPOWER);
|
||||||
radio.sleep();
|
radio.sleep();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAS_ALARM
|
||||||
|
MCUCR = (MCUCR & ~(bit(ISC01)|bit(ISC00))) | bit(ISC01); // fallende Flanke
|
||||||
|
GIMSK = (1<<PCIE0);
|
||||||
|
PCMSK0 = (1<<PCINT0); // PCINT(PA0)
|
||||||
|
pinMode(ALARM_PIN, INPUT_PULLUP);
|
||||||
|
#endif
|
||||||
|
|
||||||
// Setup LED if defined
|
// Setup LED if defined
|
||||||
#ifdef LED_PIN
|
#ifdef LED_PIN
|
||||||
pinMode(LED_PIN, OUTPUT);
|
pinMode(LED_PIN, OUTPUT);
|
||||||
|
@ -228,7 +257,6 @@ void setup()
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
// Create Data Structure for Sensor Data
|
// Create Data Structure for Sensor Data
|
||||||
|
@ -236,6 +264,11 @@ void loop()
|
||||||
struct lora_data {
|
struct lora_data {
|
||||||
uint8_t bat;
|
uint8_t bat;
|
||||||
} __attribute__ ((packed)) data;
|
} __attribute__ ((packed)) data;
|
||||||
|
#elif defined HAS_ALARM
|
||||||
|
struct lora_data {
|
||||||
|
uint8_t bat;
|
||||||
|
uint8_t alarm;
|
||||||
|
} __attribute__ ((packed)) data;
|
||||||
#elif defined HAS_SHT21
|
#elif defined HAS_SHT21
|
||||||
struct lora_data {
|
struct lora_data {
|
||||||
uint8_t bat;
|
uint8_t bat;
|
||||||
|
@ -280,6 +313,11 @@ void loop()
|
||||||
data.brightness = (int16_t)(brightness());
|
data.brightness = (int16_t)(brightness());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined HAS_ALARM
|
||||||
|
data.alarm = (uint8_t)alarm;
|
||||||
|
alarm = false;
|
||||||
|
#endif
|
||||||
|
|
||||||
// Add Battery Voltage, 20mv steps, encoded into 1 Byte
|
// Add Battery Voltage, 20mv steps, encoded into 1 Byte
|
||||||
uint32_t batv = readVcc();
|
uint32_t batv = readVcc();
|
||||||
data.bat = (uint8_t)(batv/20);
|
data.bat = (uint8_t)(batv/20);
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#define HAS_BME280 - Bosch BME280 Temperature + Humidity + Pressure Sensor
|
#define HAS_BME280 - Bosch BME280 Temperature + Humidity + Pressure Sensor
|
||||||
#define HAS_SHT21_BRIGHTNESS - SHT21 + Brightness via LED
|
#define HAS_SHT21_BRIGHTNESS - SHT21 + Brightness via LED
|
||||||
#define HAS_BME280_BRIGHTNESS - BME280 + Brightness via LED
|
#define HAS_BME280_BRIGHTNESS - BME280 + Brightness via LED
|
||||||
|
#define HAS_ALARM - send message when pin is triggered
|
||||||
|
|
||||||
* LED Support
|
* LED Support
|
||||||
#define LED_PIN PIN_A7 - LED is connected to ATTiny84 Pin A7 on TinyTX SMD / TinyLora
|
#define LED_PIN PIN_A7 - LED is connected to ATTiny84 Pin A7 on TinyTX SMD / TinyLora
|
||||||
|
@ -20,6 +21,10 @@
|
||||||
#define LED_K PIN_A7 - LED Cathode
|
#define LED_K PIN_A7 - LED Cathode
|
||||||
#define LED_A PIN_B2 - LED Anode
|
#define LED_A PIN_B2 - LED Anode
|
||||||
|
|
||||||
|
* Alarm
|
||||||
|
#define ALARM_PIN PIN_A0
|
||||||
|
if pin changed , change also PCMSK0 = (1<<PCINT0); to corrent PCINT
|
||||||
|
|
||||||
* Time between Measurements
|
* Time between Measurements
|
||||||
#define SLEEP_TIME 528 - Time in Seconds between Measurements. Try it out to get a good Approximation
|
#define SLEEP_TIME 528 - Time in Seconds between Measurements. Try it out to get a good Approximation
|
||||||
Examples from my Tests::
|
Examples from my Tests::
|
||||||
|
@ -57,5 +62,14 @@
|
||||||
#define HAS_BME280_BRIGHTNESS
|
#define HAS_BME280_BRIGHTNESS
|
||||||
#define LED_K PIN_A7
|
#define LED_K PIN_A7
|
||||||
#define LED_A PIN_B2
|
#define LED_A PIN_B2
|
||||||
#define SLEEP_TIME 544 // ca
|
#define SLEEP_TIME 544
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
// LoRa RFM95 + Alarm
|
||||||
|
#define RF_LORA
|
||||||
|
#define HAS_ALARM
|
||||||
|
#define ALARM_PIN PIN_A0
|
||||||
|
#define LED_PIN PIN_A7
|
||||||
|
#define SLEEP_TIME 544
|
||||||
|
*/
|
Loading…
Reference in a new issue