Pin High and Low Message

I am trying to make an SMS notification for my backup generator, Basically when my generator comes on because of lost of power it should send me an SMS message. Currently I have the following code working with a push button however I am trying to make it message me when the pin goes hi and when it goes low but only one time each.

<void loop()
{
if(digitalRead(genonpin)==HIGH)
{

Serial.println("button pressed");
delay(20000);
SendOnMessage();
}>

Because this is a loop if the pin stays hi it will send me messages over and over which is not what I want. Anyone has a better approach for such project?

Thanks in advance!

I am trying to make it message me when the pin goes hi and when it goes low

Take a look at the StateChangeDetection example in the IDE

Each time you read the state of the input compare it with the value the previous time you read it

Thanks I'll take a look and see how that helps. I tried to post in a code box but could not find it lol my first post hopefully I will do much better next time.

It is never too late to edit your original post :slight_smile: and include code tags

I tried to post in a code box but could not find it

See Read this before posting a programming question