에듀이노-코딩교육 전문 쇼핑몰 에듀이노-코딩교육 전문 쇼핑몰

학교, 공공기관이라면 후불결제하세요!

 
현재 위치
  1. 게시판
  2. 묻고답하기

묻고답하기

상품 게시판 상세
제목 lcd에 표시 되는 값이 선명하지 않습니다. high, low 값은 다른 용도로 쓰고 있는데 방법이 있을까요
작성자 1809967352@k (ip:)
  • 작성일 2021-07-28
  • 추천 추천하기
  • 조회수 25

안녕하세요. 너무 모르는것이 많습니다. 검색을 아무리해도 찾아 볼수없어서...문의드립니다.

아두이노+ 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;

}


평점 0점
첨부파일
비밀번호 삭제하려면 비밀번호를 입력하세요.
  • 사령관 2021-07-28 0점
    수정 삭제 댓글
    스팸글 node MCU는 3.3V지원인데 LCD는 5V동작이예요 !

    LCD가 전원공급이 원활하지않으면, 밝기가 어두워진다던지, 특정구간이 출력이 안되는 현상들이 랜덤으로 나타나게 됩니다!

    별도의 회로구성을 하는방법과, 3.3V동작의 LCD를 사용하시는것을 추천드려요 !!

    정확하게 모든것을 확인할 수 는 없지만 제가 보기에는 전원공급에대한 문제로 생각됩니다 ~
  • Ironman 2021-07-28 0점
    수정 삭제 댓글
    스팸글 보드보시면 Vin핀에 별도 5V전원을 공급해주세요!

스팸신고 스팸해제

댓글 수정

비밀번호 :

수정 취소

/ byte

비밀번호 : 확인 취소

댓글 입력

댓글달기이름 :비밀번호 : 관리자답변보기

확인

/ byte

왼쪽의 문자를 공백없이 입력하세요.(대소문자구분)

에게만 댓글 작성 권한이 있습니다.

댓글 입력

댓글달기이름 :비밀번호 :

확인

/ byte

왼쪽의 문자를 공백없이 입력하세요.(대소문자구분)

에게만 댓글 작성 권한이 있습니다.

«
»