Detecting positive edge (not digital input)


I'm using Arduino Mega communicating over Modbus TCP with my PLC.
Arduino is connected to mp3 player, to reproduce audio file every time I send command from PLC.
Communication works fine, but I have problem that I need to read command (coil state) from PLC just for moment (positive edge) to avoid file is constantly repeating while coil that I read over Modbus is on state "1".

At this moment I'm using just digital read, that is not functioning for me...

if ( Mb.C == HIGH) { (x);

So, my "X" coil has HIGH state for some time, and during that time audio file just keeps repeating (which makes sense), like I'm constantly pushing play button on player...

Any tip would be great...

You would have to use "RISING_EDGE" interrupt to trigger the play, and not "HIGH LEVEL"

see attachInterrupt examples

You should post code according to the forum guidelines: Read this before posting a programming question ...

You don't have to use an interrupt. You can just detect a change in state of the input as this example shows: StateChangeDetection