i build a systeme to measure the vertical jump
for this i use a barier infrared , i would to use the millis fonction to measure time
when there is an obstacle millis =0
and when there is no obstacle start millis
and when there is an obstacle stop millis
and i want to get this time and used in fonction
millis() does not work this way. There is no way to set it to zero. However, there is no easy way to set the clock on your wall to zero either.
Get the value of millis() when there is a change from obstacle to no obstacle.
Get the value of millis() again when there is a change from no obstacle to obstacle.
The difference of these two values will give you the number of milliseconds for the vertical jump.
What is the question?
ok can you give an exemple of the programme
Look at the blink without delay example sketch. If you record the value of millis() at the start of an interval, you can subtract that from the value of millis() taken later on to work out how much time has elapsed since the start of the interval.
This code might not compile but gives you an idea:
unsigned long startMillis = 0;
unsigned long stopMillis = 0;
unsigned long duration = 0;
byte infraredPin = 1;
void setup()
{
Serial.begin(9600);
}
void loop()
{
if(digitalRead(infraredPin) == 0)
{
startMillis = millis();
while(digitalRead(infraredPin) == 0)
{
//Do nothing and wait
}
stopMillis = millis();
duration = stopMillis - startMillis;
Serial.println(duration);
}
}
Tip: use microseconds for measuring short durations, for better accuracy.
Here a Sketch that works that uses the info. that was presented.
/*
Using an LED to simulate a duration of time, and another as a timout alarm.
*/
int ledPin = 13;//Board Pin.
int ledPinA = 11;//Led on breadboard. Use with 330 Ohm Resistor.
int delayTime = 1000;
unsigned long startMillis = 0;
unsigned long stopMillis = 0;
unsigned long duration = 0;
void setup()
{
Serial.begin(9600);
pinMode(ledPin,OUTPUT);
pinMode(ledPinA,OUTPUT);
}
//---
void loop()
{
ledOnOff();//Function 1. See below.
}
//---Function 1.
void ledOnOff()
{
digitalWrite(ledPin,HIGH);
startMillis = millis();
delay(delayTime);
int ledState = digitalRead(ledPin);
Serial.print("LED/Pin 13 is: ");
Serial.println(ledState);
digitalWrite(ledPin,LOW);
stopMillis = millis();
duration = stopMillis - startMillis;
Serial.println(duration);
ledPinAAlarm(duration);//Function 2. Passing duration value.
delay(delayTime);
ledState = digitalRead(ledPin);
Serial.print("LED/Pin 13 is: ");
Serial.println(ledState);
}
//---Function 2
void ledPinAAlarm(unsigned long funcDuration)//Receiving duration value.
{
if(funcDuration < 1000)
{
digitalWrite(ledPinA,HIGH);
}
else
{
digitalWrite(ledPinA,LOW);
}
}
@COhio, it's great of you to help.
But please edit your post to put your code within code tags so it looks like this
This is exaplained in the How to Use the Forum.
...R