use power save

This commit is contained in:
Nicu Hodos 2021-12-22 15:55:39 +01:00
parent dc562ca353
commit d1cd5d6560
2 changed files with 36 additions and 6 deletions

View File

@ -15,3 +15,12 @@ framework = arduino
lib_extra_dirs =
../libraries
~/Arduino/libraries
upload_protocol = stk500v1
; each flag in a new line
upload_flags =
-P$UPLOAD_PORT
-b$UPLOAD_SPEED
; edit these lines
upload_port = /dev/ttyACM0
upload_speed = 19200

View File

@ -1,16 +1,18 @@
#include <Arduino.h>
#include <Tiny.h>
#include <TinyPower.h>
#include <SoftwareSerial_Tiny.h>
#define DEBUG 0
#define SEND_INTERVAL (int)(5*60/8)
// Pins
#define SENDER 1
#define SENDER PIN_B4
#define TEMP_PIN A1
#if DEBUG
#define RxD 3
#define TxD 4
#define RxD PIN_B3
#define TxD PIN_B4
SoftwareSerial AttinySerial(RxD, TxD);
#endif
@ -18,20 +20,28 @@ int readTemp();
TempSensor sensor = TempSensor(TEMP_SENSOR, SENDER);
int counter = 0;
volatile int counter = 0;
volatile bool shouldSend = true;
void setup() {
#if DEBUG
AttinySerial.begin(9600);
AttinySerial.println("starting...");
#endif
sensor.setup();
analogReference(INTERNAL);
TinyPower::setup();
TinyPower::enableWdt(WDTO_8S);
}
void loop() {
sensor.sendTemp(readTemp());
delay(60000L);
if (shouldSend) {
shouldSend = false;
sensor.sendTemp(readTemp());
}
TinyPower::sleep();
}
int readTemp() {
@ -53,3 +63,14 @@ int readTemp() {
#endif
return roundf(temperatureC * 10);
}
ISR(PCINT0_vect) {
}
ISR(WDT_vect) {
counter++;
if (counter % SEND_INTERVAL == 0) {
shouldSend = true;
counter = 0;
}
}