Last active
August 29, 2015 14:05
-
-
Save amirhaleem/86ce66039919ac986579 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <SoftwareSerial.h> | |
#include <helium.h> | |
HeliumModem *modem; | |
void setup() { | |
modem = new HeliumModem(); | |
} | |
void loop() { | |
static u32 lastTime; | |
u32 time; | |
time = millis(); | |
if (time - lastTime > 5000) { | |
lastTime = time; | |
DataPack dp(1); | |
dp.appendFloat((float)get_temp()); | |
modem->sendPack(&dp); | |
} | |
} | |
// return onboard temperature in degrees celcius | |
double get_temp(void) { | |
unsigned int wADC; | |
double t; | |
// set the internal reference and mux | |
ADMUX = (_BV(REFS1) | _BV(REFS0) | _BV(MUX3)); | |
ADCSRA |= _BV(ADEN); // enable the ADC | |
delay(20); // wait for voltages to become stable | |
ADCSRA |= _BV(ADSC); // start the ADC | |
// detect end-of-conversion | |
while (bit_is_set(ADCSRA, ADSC)); | |
// reading register "adcw" takes care of how to read adcl and adch | |
wADC = ADCW; | |
t = (wADC - 324.31) / 1.22; | |
// convert to F | |
t = ((t * 9) / 5) + 32; | |
return t; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment