need help with serial.println

Hi everyone,

this is my program:
void setup(){

void loop{
Serial.println("start time");
Serial.println("stop time");

I want the Serial.println to show (start time) and (stop time) only one time when pin 40 condition changed.

thank you

Don't print when the pin is HIGH or LOW, but only when it becomes HIGH or LOW - you need to save the state of the pin last time you looked at it.
Check out the state change example in the IDE.

I didn't understand what you mean can you explain more,and which example you mean in IDE?

loop() is called repeatedly. To achieve what you want (AWOL's reply 'translated' :wink: )

if pin changes from low to high, print start time
if pin changes from high to low, print endtime

In the IDE, file ->examples -> digital -> statechangedetection