Untitled

mail@pastecode.io avatar
unknown
c_cpp
3 years ago
904 B
2
Indexable
Never
//Libs included
#include <LiquidCrystal_I2C.h>
#include <Wire.h>

//global_variables
int analog_reader_a1 = 0;
unsigned long timer_start = 0;
unsigned long timer_end = 0;
unsigned long timer_total = 0;
float capacitance = 0;
int permanent_loop = 0;
LiquidCrystal_I2C lcd (0x27, 2, 16);


//setup code that will be executed once
void setup ()
{
  pinMode(2, OUTPUT);
  Serial.begin(9600);
}
//looping code
void loop ()
{
  capacitance_meter();                    
}

int capacitance_meter()
{
  digitalWrite(2, HIGH);
  timer_start=millis();
  while (permanent_loop==0)
  {
    if (analogRead(A1) > 647)
    {
      timer_end=millis();
      timer_total=(timer_end-timer_start);
      capacitance=(float)timer_total/1000/150000;
      Serial.println(capacitance,10);
      digitalWrite(2,LOW);
      delay(timer_total*2);
      capacitance_meter();
    }
  }
}