Arduino UNO + LCD + Push buttons
LCD와 UNO WIRE 연결
LCD GND - UNO GND
LCD VCC - UNO 5V
LCD SDA - UNO A5
LCD SCL - UNO A4
[아두이노 코드]는 위 참조 링크에서 다운 받을 수 있는 링크를 다시 소개 하고 있습니다.
//Compatible with the Arduino IDE 1.0
//Library version:1.1
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd = LiquidCrystal_I2C(0x27, 20, 4); // set the LCD address to 0x27 for a 20 chars and 4 line display
// this constant won't change:
const int Up_buttonPin = 2; // the pin that the pushbutton is attached to
const int Down_buttonPin = 3;
// Variables will change:
int buttonPushCounter = 0; // counter for the number of button presses
int up_buttonState = 0; // current state of the up button
int up_lastButtonState = 0; // previous state of the up button
int down_buttonState = 0; // current state of the up button
int down_lastButtonState = 0; // previous state of the up button
bool bPress = false;
void setup()
{
Serial.begin(9600);
Wire.begin();
pinMode( Up_buttonPin , INPUT_PULLUP);
pinMode( Down_buttonPin , INPUT_PULLUP);
lcd.begin(20,4);
lcd.init(); // initialize the lcd
// Print a message to the LCD.
lcd.backlight();
// lcd.noBacklight();
lcd.setCursor(0,0);
lcd.print("Please Select:");
lcd.setCursor(2,1);
lcd.print(buttonPushCounter);
}
void loop()
{
checkUp();
checkDown();
if( bPress){
bPress = false;
lcd.setCursor(2,1);
lcd.print(" ");
lcd.setCursor(2,1);
lcd.print(buttonPushCounter);
}
}
void checkUp()
{
up_buttonState = digitalRead(Up_buttonPin);
// compare the buttonState to its previous state
if (up_buttonState != up_lastButtonState) {
// if the state has changed, increment the counter
if (up_buttonState == LOW) {
bPress = true;
// if the current state is HIGH then the button went from off to on:
buttonPushCounter++;
Serial.println("on");
Serial.print("number of button pushes: ");
Serial.println(buttonPushCounter);
} else {
// if the current state is LOW then the button went from on to off:
Serial.println("off");
}
// Delay a little bit to avoid bouncing
delay(50);
}
// save the current state as the last state, for next time through the loop
up_lastButtonState = up_buttonState;
}
void checkDown()
{
down_buttonState = digitalRead(Down_buttonPin);
// compare the buttonState to its previous state
if (down_buttonState != down_lastButtonState) {
// if the state has changed, increment the counter
if (down_buttonState == LOW) {
bPress = true;
// if the current state is HIGH then the button went from off to on:
buttonPushCounter--;
Serial.println("on");
Serial.print("number of button pushes: ");
Serial.println(buttonPushCounter);
} else {
// if the current state is LOW then the button went from on to off:
Serial.println("off");
}
// Delay a little bit to avoid bouncing
delay(50);
}
// save the current state as the last state, for next time through the loop
down_lastButtonState = down_buttonState;
}
그러나 BackLight high상태로 글씨가 잘 보이지 않지만 회로 연결 잘하고, 다운 받은 코드 업로드 실행하면 잘 잘동됩니다. 위 코드에서 하이라이트 한부분이 20*4 lcd 사용을 위해 조금 변경한 것 뿐입니다.
배터리를 절약하려는 경우 백라이트만 끄면 LCD 드라이버 자체에 전원이 공급된다는 점을 명심하십시오.
'ERP.MES.SMART FACTORY' 카테고리의 다른 글
제조공장 산업용 단말기 비교 (0) | 2023.04.26 |
---|---|
NodeMCU + LCD + 2 Push buttons (0) | 2021.07.29 |
Visual Basic .NET + Arduino IDE + NodeMCU + LCD 20*4 (0) | 2021.07.27 |
DIY DIGITAL COUNTER - NODEMCU(1) (0) | 2021.07.26 |
개인 사업자 - 세무 대리인 지정 (0) | 2021.04.18 |
댓글