title: How to execute a function just once in the void loop?
body: <p>Simply, I want to make a counter to execute a subroutine if digital read gets a toggle value just thefirst time. But the result shows that the "aFunction" executes more than once (repeatedly).</p>
  
  <p>Code:</p>
  
  <pre class="lang-cpp prettyprint-override"><code>int lastState = 1;
  
  void setup() {
      Serial.begin(115200);
  }
  
  void loop() {
      int currentState = digitalRead(D5);      
      if (currentState == 1) {
          if (currentState = !lastState) {
              aFunction();
          }
          lastState = !lastState;
      }
      Serial.println("Still running loop");     
      delay(2000);
  }
  
  void aFunction() {
      Serial.println("in a function");
  }
  </code></pre>