안녕하세요. 너무 모르는것이 많습니다. 검색을 아무리해도 찾아 볼수없어서...문의드립니다.
아두이노+ LCD + 2 Push buttons 에서 구현한것을
NODEMCU에서는 핀D2를 LCD도 써야 하고, 버튼도 써야해서 arduino uno에서 2, 3에 연결했던 것을
nodeMCU에서는 , GPIO12 = D6, GPIO13 = D7 로 연결 했습니다.
업로드하고, 작동은 되는데 LCD에 숫자가 CLEAR하지 않게 표시됩니다.
코드는 아래와 같습니다.
//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 Down_buttonPin = 12; // the pin that the pushbutton is attached to GPIO12 = D6
const int Up_buttonPin = 13; // the pin that the pushbutton is attached to GPIO13 = D7
// 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
bool aPress = true;
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();
// Wire.begin(SDA, SCL); // NODEMCU/ESP default ist D2 = 4 = SDA ; D1 = 5 = SCL
//Wire.begin(4, 5); // NODEMCU geht
//Wire.begin(D5, D6);
pinMode( Up_buttonPin , INPUT_PULLUP);
pinMode( Down_buttonPin , INPUT_PULLUP);
lcd.begin();
// 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);
}
else{
aPress = true;
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;
}
LCD가 전원공급이 원활하지않으면, 밝기가 어두워진다던지, 특정구간이 출력이 안되는 현상들이 랜덤으로 나타나게 됩니다!
별도의 회로구성을 하는방법과, 3.3V동작의 LCD를 사용하시는것을 추천드려요 !!
정확하게 모든것을 확인할 수 는 없지만 제가 보기에는 전원공급에대한 문제로 생각됩니다 ~