title: How to send a variable's value only once when a push button is released?
body: <p>So I have a push button that changes a variable value, which controls a motor's strength, when pressed. It goes through a loop back and forth and stops when I release it.</p>
  
  <p>The problem is that whenever the value changes it's being sent to the motor. I want the value to change when I press the button (without sending it to the motor) and when I'll release the button the value will be sent once to the motor (instead of the motor will change its strength very fast all the time and shake).</p>
  
  <p>Here's what I have:</p>
  
  <pre><code>increment = 1;
          void update() {
              if (millis() - last_update &gt; 300) {
                  last_update = millis();
                  strength += increment;
                  analogWrite(LAUNCHER_PIN, strength);
                  Serial.print("Canon strength: ");
                  Serial.print(strength);
                  if (strength &lt;= CANON_MIN || strength &gt;= CANON_MAX) increment = -increment;
              }
          }
  if (!digitalRead(MOTOR_BTN_PIN)) update();
  </code></pre>