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.
- Save the last state of the button
- Detect state change of button
- Download the file from Releases or
- Create 'ButtonClickCheck.h' and 'ButtonClickCheck.cpp' and copy the source.
Follow the instructions below to install.
Tested on Arduino 1.8.19
Create 'ButtonClickCheck' folder in 'libraries' folder of Arduino software
Insert 'ButtonClickCheck.h', 'ButtonClickCheck.cpp'.
Launch the Arduino software and add the following code.
#include <ButtonClickCheck.h>
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);
}
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 |
- Added 'BtnPush2Set' function
- storage separation
- tidy up comments
- Added '4=First Up' function
- development completed
'Fork' the project to create a 'new branch' and then 'pull request'.
A list of non-updating contributors can be found at contributors.