Created
January 28, 2014 13:11
-
-
Save rdev5/8667346 to your computer and use it in GitHub Desktop.
This file contains 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
// See http://arduino.cc/en/Tutorial/CapacitanceMeter | |
#include <ShiftLCD.h> | |
#include <stdlib.h> | |
ShiftLCD lcd(4, 2, 3); | |
const int DISCHARGE_PIN = 5; | |
const int CHARGE_PIN = 6; | |
const int R_VALUE = 100; | |
void setup() | |
{ | |
String output = capacitance_reading(103, "uF"); // "0.01uF" | |
lcd.begin(16, 2); | |
lcd.print(output); | |
} | |
String capacitance_reading(int C_VALUE, char *c_units) | |
{ | |
String s_capacitance = String(C_VALUE).substring(0, 2); | |
String s_power = String(C_VALUE).substring(2, 3); | |
char c_capacitance[s_capacitance.length() + 1]; | |
char c_power[s_power.length() + 1]; | |
s_capacitance.toCharArray(c_capacitance, s_capacitance.length() + 1); | |
s_power.toCharArray(c_power, s_power.length() + 1); | |
int i_capacitance = atoi(c_capacitance); | |
int i_power = atoi(c_power); | |
float f_capacitance = i_capacitance * pow(10, -1 * i_power); | |
char c_value[s_capacitance.length()]; | |
int float_precision = i_power > 0 ? i_power - 1 : i_power; | |
int float_min_width = s_capacitance.length() - 1; | |
dtostrf(f_capacitance, float_min_width, float_precision, c_value); | |
String s_output = c_value; | |
s_output += c_units; | |
return s_output; | |
} | |
void loop() | |
{ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment