Key Switch Module (KY-004) [S024] 



https://www.youtube.com/watch?v=T55Ys9_6tjk


*GitHubhttps://github.com/rdiot/rdiot-s024.git


* Specs

The Keyes KY-004 Key Switch Module is a simple on/off Micro switch compatible with Arduino systems.   

Material: FR4

Length: 25mm

Width: 16mm

Height: 10mm

Weight: 1.5g

Operating Voltage: 5v DC


* Contents

- Key Code

#include <Wire.h> 

#include <LiquidCrystal_I2C.h>


LiquidCrystal_I2C lcd(0x27,20,4);  // LCD2004

int R = 2;

byte lastButton = HIGH;

byte nowButton = HIGH;


void setup()

{

  lcd.init();  // initialize the lcd 

  lcd.backlight();

  lcd.print("start LCD2004");

  pinMode(R, INPUT);

  digitalWrite(R, HIGH);


  delay(1000);


  lcd.clear();

}


void loop()

{

 

  lcd.setCursor(0,0);

  lcd.print("S024:KY-004KeySwitch");


  byte nowButton = digitalRead(R);


  lcd.setCursor(0,1);

  lcd.print("value="+(String)nowButton);


  if (HIGH == lastButton)

  {

    if (LOW == nowButton)

    {

     lcd.setCursor(0,2);

     lcd.print("pushed  ");

    }

  }

  else

  {

    if (HIGH == nowButton)

    {

     lcd.setCursor(0,2);

     lcd.print("released");

    }

  }

 

 lastButton = digitalRead(R);

 delay(100);


}

'2) Sensor > Button' 카테고리의 다른 글

Button Switch Module [S062]  (0) 2016.09.12
Posted by RDIoT
|