showing mili second time as a decimal in the serial monitor

I am trying to build a timing system with a switch to start the time and then a IR sensor to stop the time.

I am new to writing sketches and basically I have found some code for a similar design (IR started the clock) but adapted it for the switch. I am having problems with the output to the serial monitor. it is showing as one long number and not a decimal number.... I know I can divide it by 1000 and get the correct number but I cant seem to do that in my actual code to get it to do it on the serial monitor as a decimal. I am sure that I have to change a few things from the cut code but I am not sure what needs to be adjusted.
this is my code below....

[code]

unsigned long t1=0;
unsigned long t2=0;
void sens1() { if ((t1==0) && (t2==0)) t1=millis(); }
void sens2() { if ((t2==0) && (t1!=0)) t2=millis(); }


void setup() {
  pinMode(2,INPUT);
  pinMode(3,INPUT);
  attachInterrupt(0,sens1,RISING);
  attachInterrupt(1,sens2,RISING);

  Serial.begin(115200);
}

void loop() {
  digitalWrite(13,t1?HIGH:LOW);
  if (t2>0)
    {
       
       Serial.println(t2-t1);
     t1=t2=0;
    
    }
 }

[/code]

Hello please post the serial monitor output because I can’t make sense of your question. As described I would expect the output to be a decimal number but you seem to be saying it’s not.

You haven't followed all the caveats for interrupt service routines. Rather than look further than the two that I see right away, why not you do the reading, fix it and come back if it doesn't work after that...
https://www.gammon.com.au/interrupts
Otherwise this thread will become a series of "oh, and this too..."

I can tell you that you are treating a timing variable as a boolean value in your ternary expression. That is so strange that if you did it on purpose, you should document it with inline comments. But I suspect maybe no.

Thanks for using code tags, though...

Start by declaring t1 and t2 as volatile as they are updated in the ISRs and used in loop()

You would be better off NOT using interrupts and just polling the signals for LOW to HIGH transitions. Is your button wired with a pullup or pulldown resistor? Usually a button is wired to GND and the internal pullup resistor is used, therefore you would look for a HIGH to LOW transition to determine a button has been pressed.

cnak:
I know it would be nice if I new more about this so I can be clearer of what I am trying to do.

Well, 200 years ago, there were no digital computers. Humanity didn't just get stuck because there was no existing knowledge.

Instead of wishing, you can follow an incremental learning path that begins almost at zero. Every expert on this forum once knew absolutely nothing about computers.

In fact, the Arduino hardware/software environment is tailored to such learning. But people try to take short cuts and don't understand why they don't understand... :slight_smile:

Not 200 years, but time is catching up - Babbage's Analytical Engine machine was 180 years ago now ...

How can I declare t1 and t2 as volatile?

A little research would have shown you

volatile unsigned long t1=0;
volatile unsigned long t2=0;

getting rid of the interrupts.... I assume there is more to it then just deleting the lines

Yes, of course
Look at the examples using digitalRead() in the IDE and read your input pins using it in loop()

My guess is the OPs serial monitor is not set to 115200 and so the serial output is just jibberish.
Make sure your serial speed is set to the same as your program in the IDE serial monitor window (look at the bottom right).