use power save
This commit is contained in:
parent
dc562ca353
commit
d1cd5d6560
@ -15,3 +15,12 @@ framework = arduino
|
|||||||
lib_extra_dirs =
|
lib_extra_dirs =
|
||||||
../libraries
|
../libraries
|
||||||
~/Arduino/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
|
||||||
|
|||||||
@ -1,16 +1,18 @@
|
|||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <Tiny.h>
|
#include <Tiny.h>
|
||||||
|
#include <TinyPower.h>
|
||||||
#include <SoftwareSerial_Tiny.h>
|
#include <SoftwareSerial_Tiny.h>
|
||||||
|
|
||||||
#define DEBUG 0
|
#define DEBUG 0
|
||||||
|
#define SEND_INTERVAL (int)(5*60/8)
|
||||||
|
|
||||||
// Pins
|
// Pins
|
||||||
#define SENDER 1
|
#define SENDER PIN_B4
|
||||||
#define TEMP_PIN A1
|
#define TEMP_PIN A1
|
||||||
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
#define RxD 3
|
#define RxD PIN_B3
|
||||||
#define TxD 4
|
#define TxD PIN_B4
|
||||||
SoftwareSerial AttinySerial(RxD, TxD);
|
SoftwareSerial AttinySerial(RxD, TxD);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -18,20 +20,28 @@ int readTemp();
|
|||||||
|
|
||||||
TempSensor sensor = TempSensor(TEMP_SENSOR, SENDER);
|
TempSensor sensor = TempSensor(TEMP_SENSOR, SENDER);
|
||||||
|
|
||||||
int counter = 0;
|
volatile int counter = 0;
|
||||||
|
volatile bool shouldSend = true;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
AttinySerial.begin(9600);
|
AttinySerial.begin(9600);
|
||||||
|
AttinySerial.println("starting...");
|
||||||
#endif
|
#endif
|
||||||
sensor.setup();
|
sensor.setup();
|
||||||
analogReference(INTERNAL);
|
analogReference(INTERNAL);
|
||||||
|
|
||||||
|
TinyPower::setup();
|
||||||
|
TinyPower::enableWdt(WDTO_8S);
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
sensor.sendTemp(readTemp());
|
if (shouldSend) {
|
||||||
delay(60000L);
|
shouldSend = false;
|
||||||
|
sensor.sendTemp(readTemp());
|
||||||
|
}
|
||||||
|
TinyPower::sleep();
|
||||||
}
|
}
|
||||||
|
|
||||||
int readTemp() {
|
int readTemp() {
|
||||||
@ -53,3 +63,14 @@ int readTemp() {
|
|||||||
#endif
|
#endif
|
||||||
return roundf(temperatureC * 10);
|
return roundf(temperatureC * 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ISR(PCINT0_vect) {
|
||||||
|
}
|
||||||
|
|
||||||
|
ISR(WDT_vect) {
|
||||||
|
counter++;
|
||||||
|
if (counter % SEND_INTERVAL == 0) {
|
||||||
|
shouldSend = true;
|
||||||
|
counter = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user