Created
April 6, 2016 15:30
-
-
Save Robotonics/a404f5fdaab3418ebd63aef67c24d46f to your computer and use it in GitHub Desktop.
fuel.ino
This file contains hidden or 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
// 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