#include "Arduino.h"
#include <Tiny.h>
#include <SoftwareSerial_Tiny.h>

#define DEBUG 0

// Pins
#define SENDER 1
#define TEMP_PIN A1

#if DEBUG
#define RxD 3
#define TxD 4
SoftwareSerial AttinySerial(RxD, TxD);
#endif

TempSensor sensor = TempSensor(TEMP_SENSOR, SENDER);

int counter = 0;

void setup() {

#if DEBUG
	AttinySerial.begin(9600);
#endif
	sensor.setup();
	analogReference(INTERNAL);
}

void loop() {
	sensor.sendTempAndVoltage(readTemp());
	delay(60000L);
}

int readTemp() {
	int reading = analogRead(TEMP_PIN);
#if DEBUG
	AttinySerial.println(reading);
#endif

	float voltage = reading * (1100 / 1024.0);
#if DEBUG
	AttinySerial.print(voltage);
	AttinySerial.println(" mili volts");
#endif

	float temperatureC = (voltage - 500) / 10;
#if DEBUG
	AttinySerial.print(temperatureC);
	AttinySerial.println(" degrees C");
#endif
	return roundf(temperatureC * 10);
}
