Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int msrin = 10;
- int refin = 11;
- int led = 13;
- int compout = 9;
- long microstart = 0;
- long microend = 0;
- int msrinput = 0;
- long calced1;
- float calced;
- void setup() {
- Serial.begin(9600);
- pinMode(msrin, OUTPUT);
- pinMode(refin, OUTPUT);
- pinMode(led, OUTPUT);
- pinMode(compout, INPUT);
- }
- void loop() {
- digitalWrite(msrin, HIGH);
- digitalWrite(refin, LOW);
- while (1)
- {
- msrinput = digitalRead(compout);
- if (msrinput == 0)
- {
- microstart = micros();
- break;
- }
- }
- while (1)
- {
- microend = micros();
- if ((microend - microstart) >= 100000)
- {
- break;
- }
- }
- digitalWrite(msrin, LOW);
- digitalWrite(refin, HIGH);
- microstart = micros();
- while(1) //check if cap is uncharged
- {
- msrinput = digitalRead(compout);
- if (msrinput == 1)
- {
- microend = micros();
- calced1 = (microend - microstart);
- calced = 2.52 * (calced1 / 100000.0);
- Serial.println(calced);
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement