Skip to content

Instantly share code, notes, and snippets.

@lawrencejones
Created July 22, 2014 15:15
Show Gist options
  • Save lawrencejones/58e1c41bb119f8158699 to your computer and use it in GitHub Desktop.
Save lawrencejones/58e1c41bb119f8158699 to your computer and use it in GitHub Desktop.
Variadic function to enable easy writing to serial char device on an arduino
#include <cstdarg.h>
void writeValues(int count, ...)
{
/* Declare variadic args */
va_list ap;
va_start(ap, count);
Serial.print("#S|SAVEDATA|[");
/* For each value, print to Serial */
for (int i = 0; i < count; i++)
{
Serial.print(va_arg(ap, float));
Serial.print(';');
}
Serial.print("]#");
va_end(ap);
}
writeValues
( 3
, humidity
, sensors.getTempC(fanThermometer)
, sensors.getTempC(airThermometer) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment