I want to draw your attention.
It's hard to read descriptions of the trigger, and the reason is not English
'N = X, where X is 1 - if last and previous values differs, 0 - otherwise.'
might be simpler and more important - more readable like this:
'N = 1 - if last and previous values differs, 0 - otherwise.'
Why use such complex design of the word?
I strongly recommend you to consider this improvement.
I copied the English text is 100% as he was, but take a look to attached picture, I hope you will understand something, the main thing - unification, and a simple writing, which is easy to read, no extra variables of type "X" which only confuse the brain.