Skip to content

Instantly share code, notes, and snippets.

@jadudm
Last active January 2, 2016 08:28
Show Gist options
  • Save jadudm/8276252 to your computer and use it in GitHub Desktop.
Save jadudm/8276252 to your computer and use it in GitHub Desktop.
A simple sense-log-sleep loop for the TMP36.
/**************************************
* VARIABLES AND PINS
**************************************/
/* Declare a variable to store the sensor reading. */
int theReading;
/* Declare the pin we have attached the sensor to. */
int TMP36 = A0;
/**************************************
* SETUP
**************************************/
void setup () {
/* Set the speed that we send data to the SD card. */
Serial.begin(9600);
}
/**************************************
* LOOP
**************************************/
void loop () {
/* Read from the sensor. */
theReading = analogRead(TMP36);
/* Print the value. This sends it to the SD card. */
Serial.println(theReading);
/* Wait for 10 seconds (for testing purposes). Later, we'll change this. */
waitMinsSecs(0, 10);
}
/**************************************
* HELPER FUNCTIONS
**************************************/
/* FUNCTION:
waitMinsSecs(mins, secs)
PURPOSE:
A fancy version of "delay".
USE:
waitMinsSecs(1, 0) would wait one minute and zero seconds.
waitMinsSecs(5, 30) would wait five minutes and 30 seconds.
waitMinsSecs(0, 5) would wait zero minutes and five seconds.
*/
void waitMinsSecs (int mins, int secs) {
int m, s;
/* Loop for the number of minutes the programmer specified.
This could be zero, in which case, nothing happens here.
*/
for (m = 0; m < mins; m++) {
for (s = 0 ; s < 60; s++) {
delay(1000);
}
}
/* Loop for the number of seconds the programmer specified.
This could also be zero, in which case, nothing happens here, either.
*/
for (s = 0; s < secs; s++) {
delay(1000);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment