Skip to content

Instantly share code, notes, and snippets.

@Robotonics Robotonics/fuel.ino
Created Apr 6, 2016

Embed
What would you like to do?
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
You can’t perform that action at this time.