make flags

Hello people,
can I ask you for your help.
I have some sensor, which have two states (HIGH, LOW) and depends of the status I send notification to Telegram.
I not sure, how to make flags - when the status is changed to send just one message to my Telegram until the status change again.
Can you give me hand or example, how to program this ?

Sure, here is a simple example where a flag is used to indicate the on/off state of an LED.
The flag is called ledState.

#define LED 13

const unsigned long eventInterval = 1000000;
unsigned long previousTime = 0;
byte ledState = 0;

void setup()
// put your setup code here, to run once:
{
  Serial.begin(9600);
  pinMode (LED, OUTPUT);
}
// probably needs loop here:
void loop()
{
  unsigned long currentTime = micros( );
  if (currentTime - previousTime >= eventInterval)
  {
    ledState = 1 - ledState; // result is 1, 0, 1, 0 ...
    previousTime = previousTime + eventInterval;
    digitalWrite (LED, ledState);
    Serial.println (previousTime);
  }
} // needs this to end loop()

Not sure, that this help to me.
Mostly like this - i will explain not in programming language:

status = 0
status changed to 1
send notification
status not change -> do nothing
status is changed to 0
send notification

and so on.

There is an example for that:

File->Examples->02.Digital->StateChangeDetection

Looks, this I need :slight_smile:
Just one additional question:
how to read/understand this one :

if (buttonPushCounter % 4 == 0) {

in the example is described, that this is 4 times pushing, but I don't know how this work. What mean %4

That is discussed here
https://www.arduino.cc/reference/en/language/structure/arithmetic-operators/remainder/

What mean %4

It means divide by 4 and return the remainder.

So

buttonPushCounter % 4 == 0

will only be true when buttonPushCounter is exactly divisible by 4