Solenoid firing

I’m having a coding issue and I’m sure its an easy fix but I can’t figure it out. I’m using an accelerometer to detect an angle and then pull a solenoid for 300ms then let go. However, I want it to do this only one time when an angle > 20deg is read. With my code now, it keeps pulling until it reads an angle < 20deg. How can I change my code to make that happen?


if (ydegrees < -20 or ydegrees > 20) {
digitalWrite(Solenoid, HIGH);
digitalWrite(Solenoid, LOW);

digitalWrite(Solenoid, LOW);

Have a variable that is set when >20 and reset when <20.
Test this variable, if it is reset and >20 fire the solenoid and set the variable.

Would anyone be able to help me out with the above coding suggestion? I still cant figure it out and I know its so simple :stuck_out_tongue_closed_eyes:

Example StateChangeDetection in 02.Digital.