Tact Switch PC Horizontal 5,0mm
  • Tact Switch PC Horizontal 5,0mm
  • Tact Switch PC Horizontal 5,0mm

Tact Switch PC Horizontal 6x6mm

: CEL10014
€0.15
Tax included

PCB mount 6x6mm, max. 50mA/24V, upthrow 0,5mm, activation power 1,6N.

Quantity

If you have any questions on this product please feel free to contact us.

*Disclaimer: The images are merely illustrative.

If you have any questions on this product please feel free to contact us.

*Disclaimer: The images are merely illustrative.

/* Learn to use pushbutton (button switch) with Arduino - Tutorial
   More info and circuit schematic: http://www.ardumotive.com/arduino-tutorials/category/button
   Dev: Michalis Vasilakis / Date: 19/10/2014  
   UPDATED 2/6/2016 - LED to Arduino pin 3 and button to Arduino pin 4*/


//Constants
const int buttonPin = 4;     
const int ledPin =  3;     

//Variables
int buttonState = 0;
int flag=0;

void setup() {
  //Input or output?
  pinMode(ledPin, OUTPUT);      
  pinMode(buttonPin, INPUT_PULLUP);   
}

void loop(){
  //Read button state (pressed or not pressed?)
  buttonState = digitalRead(buttonPin);

  //If button pressed...
  if (buttonState == LOW) { 
    //...ones, turn led on!
    if ( flag == 0){
      digitalWrite(ledPin, HIGH);
      flag=1; //change flag variable
    }
    //...twice, turn led off!
    else if ( flag == 1){
      digitalWrite(ledPin, LOW);
      flag=0; //change flag variable again 
    }    
  }
  delay(200); //Small delay

}

esquema

 

CEL10014

Download

KSM612B.png

Download (31.72k)

Related products