Button Code

So im very very new to arduinos, and I was wondering if someone can quickly make me a button code( because i have no clue after reading everything)

What the arduino pretty much needs to do is,

Start a timer when an electrical circuit is incomplete.

Stop a time when the electrical circuit is complete.

Time difference into an equation h= 9.8t^2/8 (t being the time difference)

Then the equation being sent to the COM or Java program that displays it.

Thank you whoever does this! should be quick and simple for you guys since the things ive seen on this site are 1000000x more complex :stuck_out_tongue:

COMPLETELY UNTESTED CODE
But it might get you a step closer.

const byte input = 12;

unsigned long startTime;

void setup()
{
      Serial.begin(9600);
      pinMode(input,INPUT);
}

void loop() 
{
      if (digitalRead(input)==LOW)
      {
            startTime = millis();
            while (digitalRead(input)==LOW) {/*wait for it to change back*/}
            float s = ((millis()-startTime)/1000.0f);
            float h = 9.81 * s * s / 8;
            Serial.println(h);
      }
}

nothing showed up on the com :frowning:

what does this do:

const byte input = 12;

unsigned long startTime;

void setup()
{
      Serial.begin(9600);
      pinMode(input,INPUT);
}

void loop()
{
      if (digitalRead(input)==HIGH)
      {
            startTime = millis();
            while (digitalRead(input)==HIGH) {/*wait for it to change back*/}
            float s = ((millis()-startTime)/1000.0f);
            float h = 9.81 * s * s / 8;
            Serial.print("h = ");
            Serial.println(h);
      }
}