63 lines
1.2 KiB
C++
63 lines
1.2 KiB
C++
#include "Arduino.h"
|
|
#include <Tiny.h>
|
|
|
|
// Pins
|
|
#define SENDER 2
|
|
#define TEMP_PIN 3
|
|
|
|
#define SENSOR_ID 4
|
|
|
|
TempSensor sensor = TempSensor(SENSOR_ID, SENDER);
|
|
|
|
int counter = 0;
|
|
|
|
void setup() {
|
|
|
|
Serial.begin(9600);
|
|
|
|
sensor.setup();
|
|
|
|
// TinyPower::setup();
|
|
// TinyPower::enableWdt(WDTO_8S);
|
|
}
|
|
|
|
void loop() {
|
|
// TinyPower::sleep();
|
|
unsigned long value = sensor.sendTempAndVoltage(readTemp());
|
|
Serial.println(value);
|
|
delay(5000);
|
|
}
|
|
|
|
int readTemp() {
|
|
int reading = analogRead(TEMP_PIN);
|
|
|
|
// converting that reading to voltage, for 3.3v arduino use 3.3
|
|
float voltage = reading * 5.0;
|
|
voltage /= 1024.0;
|
|
|
|
// print out the voltage
|
|
Serial.print(voltage);
|
|
Serial.println(" volts");
|
|
|
|
// now print out the temperature
|
|
float temperatureC = (voltage - 0.5) * 100; //converting from 10 mv per degree wit 500 mV offset
|
|
//to degrees ((voltage - 500mV) times 100)
|
|
Serial.print(temperatureC);
|
|
Serial.println(" degrees C");
|
|
return roundf(temperatureC*10);
|
|
}
|
|
|
|
ISR(PCINT0_vect) {
|
|
sensor.sendTempAndVoltage(readTemp());
|
|
delay(5000);
|
|
sensor.sendTempAndVoltage(readTemp());
|
|
}
|
|
|
|
ISR(WDT_vect) {
|
|
counter++;
|
|
if (counter % 220 == 0) {
|
|
counter = 0;
|
|
sensor.sendTempAndVoltage(readTemp());
|
|
}
|
|
}
|