Speed measurement using 2 Inductive sensor

Hi everyone,

I am new to Arduino and working on a project in which I have to measure train speed using 2 Inductive senosrs.

I have 2 Inputs.

Output should be 5 bit Binary code.

I am getting Speed measurement in decimal values.
I tried to convert it in Binary but its showing always 8 bits.

Is there any way to get output exactly 5 bit Binary coded.

I have attached my code below.

Thank you very much

Geschwindigkeitmessung.ino (1.17 KB)


Thank you for your reply.

I do have another query regarding this code.

I can run this whole loop only once.

but my requirment is whenever sensor goes from low to high, loop must run once

How can I do that?