how to send once then stop sending?

I can not figure out how to get this CC message to just send one time.
The message is continuously being sent out as either a 0 or 127.

This is the code i am working with.

if(touchX > 127)
{MIDI.sendControlChange(22,0,1);   //needs to be sent only once
}
else
{
MIDI.sendControlChange(22,127,1);   //needs to be sent only once
}

isn't there some way to say "just send once" or something to that effect?

Send it in "setup", or set a flag to say "I've-sent-it-so-don't-send-it-again"

i actually need it to happen over and over (each time the "touchX" value triggers it)

i tried the setup method and that didnt work out.

i actually need it to happen over and over

So why did you ask for a method to send it only once?

isn't there some way to say "just send once"

because i want it to send the message one time per trigger.

when the value is triggered as it is it sends out the message constantly slamming my midi device with non-stop messages, rather than just the one message to turn the function on.

basically i want it to operate as if it were a button sending an on then off message.
not like: on on on on on on on on on on on on on on on on off off off off off off off off off off off off off off off off off off off off off off....

So only send the message when the value changes

You could use the following:

touchXOld = 0
if(touchX > 127 && touchX <> touchXOld){
  touchXOld = touchX;
  MIDI.sendControlChange(22,0,1);   //needs to be sent only once
} else {
  MIDI.sendControlChange(22,127,1);   //needs to be sent only once
}

Which triggers when touchX is greater than 127, and then again only when touchX is greater than 127 and different to the previous value.

touchX <> touchXOld

BASIC alert!

"!="