Sunteți pe pagina 1din 3

unsigned long start, finish, contact_travel;

const int buttonPin0 = 2; // the pin that the pushbutton is attached to

const int buttonPin1 = 3; // the pin that the pushbutton is attached to

const int ledPin = 13; // the pin that the LED is attached to

int buttonState0 = 0; // current state of the button

int buttonState1 = 1; // current state of the button

int lastButtonState0 = 0; // previous state of the button

int lastButtonState1 = 1; // previous state of the button

int ledState = 0; // remember current led state

void setup()

Serial.begin(9600);

pinMode(buttonPin0, INPUT); // initialize the button pin as a 1 input

pinMode(buttonPin1, INPUT); // initialize the button pin as a 2 input

pinMode(ledPin, OUTPUT); // initialize the button pin as a output

void displayResult()

float s, ms, us;

unsigned long completed;

contact_travel = finish - start;

s = int( contact_travel/ 1000000);

completed = contact_travel %1000000;

ms = int(completed / 1000);
us = completed % 1000;

Serial.print("Measured Timing Values ");

Serial.print(s, 0);

Serial.print("s ");

Serial.print(ms, 0);

Serial.print("ms ");

Serial.print(us, 0);

Serial.print("us ");

Serial.println();

Serial.println(contact_travel);

void loop()

// read the pushbutton input pin

buttonState0 = digitalRead(buttonPin0);

// check if the button is pressed or released

// by comparing the buttonState to its previous state

if (buttonState0 != lastButtonState0)

start = micros();

digitalWrite(13,HIGH);

// remember the current state of the button


lastButtonState0 = buttonState0;

buttonState1 = digitalRead(buttonPin1);

if (buttonState1 != lastButtonState1)

{ // change the state of the led when someone pressed the button

finish = micros();

digitalWrite(13,LOW);

displayResult();

// remember the current state of the button

lastButtonState1 = buttonState1;

}}}

S-ar putea să vă placă și