Time between high signal & Low signal + During High Signal
hi everybody,
i'm new in arduino world.
i prepared test system time between 2 button signals. works problem can measure time between high & low signal or opposite. therefore, can't measure total time during button press , release.
i want calculate between first pulse of high signal , next first pulse of high signal. support me if know solution please find codes below. thank you.
i'm new in arduino world.
i prepared test system time between 2 button signals. works problem can measure time between high & low signal or opposite. therefore, can't measure total time during button press , release.
i want calculate between first pulse of high signal , next first pulse of high signal. support me if know solution please find codes below. thank you.
code: [select]
byte button =7;
int led = 8;
int buzzer = 3;
unsigned long starttime;
unsigned long endtime;
unsigned long duration;
unsigned long starttime1;
unsigned long endtime1;
unsigned long duration1;
byte timerrunning;
void setup(){
pinmode (button, input_pullup);
pinmode(led, output);
pinmode(buzzer, output);
serial.begin(9600);
}
void loop(){
if (timerrunning == 0 && digitalread(button) == low){ // button pressed & timer not running already
starttime = millis();
timerrunning = 1;
}
if (timerrunning == 1 && digitalread(button) == high){ // timer running, button released
endtime = millis();
timerrunning = 0;
duration = endtime - starttime;
serial.print ("button press time in milliseconds: ");
serial.println (duration);
digitalwrite(buzzer, high);
digitalwrite(led, high);
}
else
{
digitalwrite(buzzer, low);
digitalwrite(led, low);
}
}
at moment have 2 states - timerrunning = 0 , 1. think if introduce 3rd state can detect button has gone high , low again
something this
if have misunderstood requirement please make simple drawing showing pulse , points @ wish measure time , post photo of drawing.
...r
something this
code: [select]
if (timerrunning == 0 && digitalread(button) == low){ // button pressed & timer not running already
starttime = millis();
timerrunning = 1;
}
if (timerrunning == 1 && digitalread(button) == high){ // timer running, button released
timerrunning = 2;
}
if (timerrunning == 2 && digitalread(button) == low){ // timer running, button released
endtime = millis();
timerrunning = 0;
duration = endtime - starttime;
if have misunderstood requirement please make simple drawing showing pulse , points @ wish measure time , post photo of drawing.
...r
Arduino Forum > Using Arduino > Programming Questions > Time between high signal & Low signal + During High Signal
arduino
Comments
Post a Comment