Created
August 28, 2015 20:05
-
-
Save hopbit/44498c5cd7e3de8ab262 to your computer and use it in GitHub Desktop.
codepot2015-arduino-workshop-snippet.ino
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
#define CHARGE_PIN 13 | |
#define DISCHARGING_PIN 12 | |
#define VOLTAGE_PIN A0 | |
#define R 10000.0F | |
void setup() { | |
pinMode(CHARGE_PIN, OUTPUT); | |
digitalWrite(CHARGE_PIN, LOW); | |
Serial.begin(9600); | |
Serial.print("hello world \n"); | |
} | |
void loop() { | |
// start charging | |
long start = millis(); | |
digitalWrite(CHARGE_PIN, HIGH); | |
while(analogRead(VOLTAGE_PIN)<648) { | |
Serial.print(float((analogRead(VOLTAGE_PIN)+1))/1024*100); | |
Serial.println(" %"); | |
} | |
long elapsed = millis() - start; | |
float capacitance = float(elapsed)/R*1000; | |
Serial.print(capacitance); | |
Serial.println(" uF"); | |
// start discharging | |
digitalWrite(CHARGE_PIN, LOW); | |
pinMode(DISCHARGING_PIN, OUTPUT); // ??? | |
digitalWrite(DISCHARGING_PIN,LOW); | |
while(analogRead(VOLTAGE_PIN)>0){ | |
// discharging | |
} | |
digitalWrite(DISCHARGING_PIN,INPUT); | |
delay(1000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment