Skip to content

Instantly share code, notes, and snippets.

@Robotonics
Created April 6, 2016 15:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Robotonics/a404f5fdaab3418ebd63aef67c24d46f to your computer and use it in GitHub Desktop.
Save Robotonics/a404f5fdaab3418ebd63aef67c24d46f to your computer and use it in GitHub Desktop.
fuel.ino
// Project created by David Cotterill-Drew- Just to learn and have fun!
// 05/04/2016 23:08 GMT
#include "math.h" // needed for 'pow' and 'floor'
double fuelval; // Variable to hold voltage measurement
double fuelper; // Variable to hold battery charge as a percentage
int mic = A0; // Output of mic connected to A0 - ADC pin
int level=0; // Variavle to hold sound output measurement
FuelGauge fuel; // Initialise FuelGague object 'fuel'
double Round(double dbVal, int nPlaces) // nPlaces=2 for 2 dec places, etc,.
{
const double dbShift = pow(10.0, nPlaces);
return floor(dbVal * dbShift + 0.5) / dbShift;
}
void setup()
{
fuelval=fuel.getVCell(); // Read battery voltage from Electron
fuelper=fuel.getSoC(); // Read battery percentage from Electron
}
void loop()
{
fuelval=static_cast<double>(fuel.getVCell()); // Convert float to double
fuelper=static_cast<double>(fuel.getSoC());
fuelval=Round(fuelval,2); // round reading to 2 dec places
fuelper=Round(fuelper,0); // round reading to 0 dec places
level=analogRead(mic);
Particle.variable("Voltage" ,fuelval ); // publish variables to particle cloud
Particle.variable("Percent", fuelper);
Particle.variable("Level",level);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment