Impulsschakeling

oesp
Ik zit nog altijd met bistabiel in men hoofd. De andere opmerkingen blijven geldig.

// Pin 13 has an LED connected on most Arduino boards.
#define led  13
// in test I want to use input 34.
#define input_IO  34

// the setup routine runs once when you press reset:
void setup() {                
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT);    
 // initialize the digital pin as an input. 
  pinMode(input_IO, INPUT); 
}
 
// the loop routine runs over and over again forever:
void loop() 
{
  static byte buttonState=LOW;
  static byte releasState =LOW;
  byte newButtonState=digitalRead(input_IO);
  if (newButtonState != buttonState)
     {
        if (buttonState=HIGH)
           {
              releasState=!releasState;
            }
        buttonState=!buttonState;
     }
  digitalWrite(led,releasState);
 delay(100); //as a quick debounce solution but a real debounce would be better
}