Skip to content

dang-gun/Arduino_ButtonClickCheck

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Button Click Check (Library for Arduino)

This is a library for checking the state of a button connected to an Arduino.

Detailed explanation (Korean) : [Arduino] Button Click Check - 버튼 상태 저장 및 확인 라이브러리


Differentiate the output when the state does not change and when the state changes. Using this state, you can easily program it to act only once when the button's state changes.

설명영상

Index

Overview

  • Save the last state of the button
  • Detect state change of button

Getting Started

  • Download the file from Releases or
  • Create 'ButtonClickCheck.h' and 'ButtonClickCheck.cpp' and copy the source.

Follow the instructions below to install.

Prerequisites

Tested on Arduino 1.8.19

Installing

Create 'ButtonClickCheck' folder in 'libraries' folder of Arduino software

Insert 'ButtonClickCheck.h', 'ButtonClickCheck.cpp'.

Arduino_ButtonClickCheck_001

Launch the Arduino software and add the following code.

#include <ButtonClickCheck.h>

Running the tests

Put the code below in your sketch to test it.

#include <ButtonClickCheck.h>

#define Button01 2
#define Button02 4

//테스트 1
ButtonClickCheck BCC_1(HIGH);
//테스트 2
ButtonClickCheck BCC_2(LOW);

void setup() 
{
  Serial.begin(9600);
  
  pinMode(Button01, INPUT);
  pinMode(Button02, INPUT);
}

void loop() 
{
  
  //컴퓨터에 신호를 준다.
  int nBtnState01 = BCC_1.ClickCheck(digitalRead(Button01));
  int nBtnState02 = BCC_2.ClickCheck(digitalRead(Button02));
  
  Serial.print(nBtnState01);
  Serial.print(" : ");
  Serial.println(nBtnState02);
  
  delay(500);
}

ButtonClickCheck_001_001

ButtonClickCheck_001_003

Document

Name Description
ButtonClickCheck(int nButtonUpLevel) A library for button judgment
@param nButtonUpLevel The judgment value when the button is not pressed. LOW or HIGH
ButtonClickCheck(uint8_t uintPin, int nButtonUpLevel) Library for judging buttons (specifying which pins to use)
@param uintPin pre-assign pins.
@param nButtonUpLevel Judgment value when the button is not pressed. LOW or HIGH
   
int ClickCheck() Read the value of the stored pin number to determine the click information.
@return 1=Up, 2=Down, 3=First Down, 4=First Up

1=Up : The button is not pressed
2=Down: The button is pressed
3=First Down: The state where the button changed from Up to Down (output only once when changed)
4=First Up: The state where the button changed from Down to Up (output only once when changed)
int ClickCheck(int nDigitalRead) Read the delivered value to determine the click information.
@param nDigitalRead Input digital value (passed value)
@return 1=Up, 2=Down, 3=First Down, 4=First Up

1=Up : The button is not pressed
2=Down: The button is pressed
3=First Down: The state where the button changed from Up to Down (output only once when changed)
4=First Up: The state where the button changed from Down to Up (output only once when changed)
BtnPush2Set(bool bBtnPush2Value) Set the existing state value 'bBtnPush2' to a desired value.
@param bBtnPush2Value Data to store in the existing state value. on=true, off=false

Update history

2023-05-17 :

  • Added 'BtnPush2Set' function
  • storage separation

2023-05-15 :

  • tidy up comments

2023-05-11 :

  • Added '4=First Up' function

2019-07-28 :

  • development completed

Contributing

'Fork' the project to create a 'new branch' and then 'pull request'.

Authors

A list of non-updating contributors can be found at contributors.

License

MIT

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages