ใครพอจะแนะนำ การทำ lcd menu มั้งครับ

พอจะมีเว็บที่แนะนำการทำ LCD MENU บ้างหรือป่าวครับ

ใน arduino ออก lcd อ่ะหรอครับ

ใช่ครับผม ออก lcd Diagram ประมาณนี้อะครับ

ลองดูตัวอย่างนี้ครับ

#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2); // ARDUINO UNO
//LiquidCrystal lcd(3, 2, 1, 7, 8, 9, 10); // ATTINY84
byte buttons[] = {6,7,8}; //10 for additional pin
const byte nrButtons = 3; // change to 4 if additional button added
int menusize = 10;
String menu[] = {
  "Menu",                   //0
  "Menu>LED",               //1
  "Menu>LED>Off",           //2
  "Menu>LED>On",            //3
  "Menu>LED>Fade",          //4
  "Menu>LED>Blink",         //5
  "Menu>LCDlight",          //6
  "Menu>Nothing1",          //7  
  "Menu>Nothing2",          //8
  "Menu>Nothing3"           //9
};

int t;
byte pressedButton, currentPos,currentPosParent, possiblePos[20], possiblePosCount, possiblePosScroll = 0;
String parent = "";

int brightness;
int LCDtoggle = 0;
int fadeAmount = 5;
unsigned long timer = (millis() / 10);
int ledMode = 0;

void updateMenu () {
  possiblePosCount = 0;
  while (possiblePosCount == 0) {
    
    for (t = 1; t < menusize;t++) {
      if (mid(menu[t],1,inStrRev(menu[t],">")-1).equals(menu[currentPos])) {
        possiblePos[possiblePosCount]  =  t;
        possiblePosCount = possiblePosCount + 1;
      }
    }
    
    //find the current parent for the current menu
    parent = mid(menu[currentPos],1,inStrRev(menu[currentPos],">")-1);
    currentPosParent = 0;
    for (t = 0; t < menusize; t++) {
       if (parent == menu[t]) {currentPosParent = t;}
    }

    // reached the end of the Menu line
    if (possiblePosCount == 0) {
      //Menu Option Items
      switch (currentPos) {
        case 2:
        case 3:
        case 4:
        case 5://Choose between 2,3,4,5
          for (t = 2; t<6; t++) {
            if (mid(menu[t],len(menu[t]),1) == "*") {
              menu[t] = mid(menu[t],1,len(menu[t])-1);
            }
          }
          menu[currentPos] = menu[currentPos] + "*";
        break;
        case 6: //Toggle
          if (mid(menu[currentPos],len(menu[currentPos]),1) == "*") {
            menu[currentPos] = mid(menu[currentPos],1,len(menu[currentPos])-1);
          } else {
            menu[currentPos] = menu[currentPos] + "*";    
          }
          
        break;
      }

      //Set Variables
      switch (currentPos) {
        case 2:
          ledMode = 0;
        break;
        case 3:
          ledMode = 1;
        break;
        case 4:
          brightness = 128;
          ledMode = 2;
        break;
        case 5:
          brightness = 0;
          ledMode = 3;
        break;
        case 6:
          LCDtoggle = abs(LCDtoggle - 1);
          digitalWrite(13,LCDtoggle);
        break;
      }


      // go to the parent
      currentPos = currentPosParent;
    }
  }
    lcd.clear();
    lcd.setCursor(0,0); lcd.print(mid(menu[currentPos],inStrRev(menu[currentPos],">")+1,len(menu[currentPos])-inStrRev(menu[currentPos],">")));
    lcd.setCursor(0,1); lcd.print(mid(menu[possiblePos[possiblePosScroll]],inStrRev(menu[possiblePos[possiblePosScroll]],">")+1,len(menu[possiblePos[possiblePosScroll]])-inStrRev(menu[possiblePos[possiblePosScroll]],">")));

}

// Look for a button press
byte checkButtonPress() {
  byte bP = 0;
  byte rBp = 0;
  for (t = 0; t<nrButtons;t++) {
    if (digitalRead(buttons[t]) == 0) {bP = (t + 1);}
  }
  rBp = bP;
  while (bP != 0) { // wait while the button is still down
    bP = 0;
    for (t = 0; t<nrButtons;t++) {
      if (digitalRead(buttons[t]) == 0) {bP = (t + 1);}
    }
  }
  return rBp;
}



void setup() {
  
  lcd.begin(16,2); 
  lcd.clear();
  
  for (t=0;t<nrButtons;t++) {
    pinMode(buttons[t],INPUT_PULLUP); 
  }
  
  pinMode(13,OUTPUT);
  pinMode(9,OUTPUT);

  lcd.setCursor(0,0); lcd.print("HELLO");
  delay(1000);
  updateMenu();

}

void loop() {

  
  switch (ledMode) {
    case 0:
      analogWrite(9, 0);
    break;
    case 1:
      analogWrite(9, 255);
    break;
    case 3:
      if ((millis() / 10) - timer > 30) {
        timer = (millis() / 10);
        brightness = abs(brightness - 255);
        timer = (millis() / 10);
        analogWrite(9, brightness);
      }
    break;
    case 2:
      if ((millis() / 10) - timer > 3) {
        timer = (millis() / 10);
        analogWrite(9, brightness);
        brightness = brightness + fadeAmount;
        if (brightness <= 0 || brightness >= 255) {
          fadeAmount = -fadeAmount;
        }
      }
    break;
  }

  pressedButton = checkButtonPress();
  if (pressedButton !=0) {
    switch (pressedButton) {
      case 1:
          possiblePosScroll = (possiblePosScroll + 1) % possiblePosCount; // Scroll
      break;
      // If I wanted a 4 button controll of the menu
      //case 4:
        //  possiblePosScroll = (possiblePosScroll + possiblePosCount - 1) % possiblePosCount; // Scroll
      //break;
      case 2:
        currentPos = possiblePos[possiblePosScroll]; //Okay
      break;
      case 3:
        currentPos = currentPosParent; //Back
        possiblePosScroll = 0;
      break;
    }
    updateMenu();
  }
}

2 Likes

หรือจะเขียนลักษณะนี้ก็ได้เช่นกัน

1 Like

ผมใช้ 7HC165 ขยายขา ใช่เป็น สวิตช์​ อะครับ

ใช้ จอ LCD เป็น แบบ I2C รึป่าว

I2C ครับผม

#include <LiquidCrystal_I2C.h>
#include <Wire.h>
#include <Adafruit_AM2315.h>
#include "RTClib.h"
#include <ShiftIn.h>
#define THERMISTORNOMINAL 10000
#define TEMPERATURENOMINAL 25
#define NUMSAMPLES 5
#define BCOEFFICIENT 3950
#define SERIESRESISTOR 8000
RTC_DS1307 RTC;
LiquidCrystal_I2C lcd(0x38, 20, 4);
Adafruit_AM2315 am2315;
ShiftIn<2> shift;
float temperature, humidity;
int check_mode = 0;
int buttonMode = 3;
int b_mode = 0;
int status_mode = 0;
int buttonOk = 4;
int b_ok = 0;
int status_ok = 0;
int btnDOWN = 0;
float t1;
float tt;
int ButtonDelay = 350;
bool isMainMenu = false;
unsigned int ScreenNumber = 0;
int setting = 0;


void setup()
{
  pinMode(buttonMode  , INPUT);
  Serial.begin(9600);
  shift.begin(8, 0, 11, 12);
  RTC.begin();
  if (! RTC.isrunning()) {
    Serial.println("RTC is NOT running!");
    RTC.adjust(DateTime(__DATE__, __TIME__));
  }
  am2315.begin();
  lcd.begin();
  lcd.backlight();
  welcome();
  lcd.clear();
}

void loop()
{
  uint16_t samples1[NUMSAMPLES];
  uint16_t samples2[NUMSAMPLES];
  float average1;
  float average2;
  int i = 0;
  float factor = 7.5;

  if (! am2315.readTemperatureAndHumidity(&temperature, &humidity)) {
    return;
  }
  for (i = 0; i < NUMSAMPLES; i++) {
    samples1[i] = analogRead(A0);
    samples2[i] = analogRead(A1);
  }

  average1 = 0;
  average2 = 0;

  for (i = 0; i < NUMSAMPLES; i++) {
    average1 += samples1[i];
    average2 += samples2[i];
  }
  average1 /= NUMSAMPLES;
  average1 = 1023 / average1 - 1;
  average1 = SERIESRESISTOR / average1;

  average2 /= NUMSAMPLES;
  average2 = 1023 / average2 - 1;
  average2 = SERIESRESISTOR / average2;

  t1 = average1 / THERMISTORNOMINAL;          // (R/Ro)
  t1 = log(t1);                               // ln(R/Ro)
  t1 /= BCOEFFICIENT;                         // 1/B * ln(R/Ro)
  t1 += 1.0 / (TEMPERATURENOMINAL + 273.15); // + (1/To)
  t1 = 1.0 / t1;                              // Invert
  t1 -= 273.15;                               // convert to C

  tt = average2 / THERMISTORNOMINAL;          // (R/Ro)
  tt = log(tt);                               // ln(R/Ro)
  tt /= BCOEFFICIENT;                         // 1/B * ln(R/Ro)
  tt += 1.0 / (TEMPERATURENOMINAL + 273.15); // + (1/To)
  tt = 1.0 / tt;                              // Invert
  tt -= 273.15;

  Serial.print(t1); Serial.print(":*C Temp1 ");
  Serial.println();
  Serial.print(tt); Serial.print(":*C Temp2 ");
  Serial.println();
  if (shift.update())
    displayValues();
  Serial.print("Temp *C: "); Serial.println(int(temperature));
  Serial.print("Hum %: "); Serial.println(int(humidity));
  ////////////////////////////////////////
  b_mode = digitalRead(buttonMode);
  b_ok = digitalRead(buttonOk);
  if (setting == 0) {
    mainpage();
  }
  if (b_mode == LOW) {
    lcd.clear();
    setting = 1;
    delay(ButtonDelay);
  }
  switch (setting)
  {
    case 1:
      {
        setting = 2;
        Serial.println(setting);
        InternalScreen0();
        break;
      }
  }
  if (shift.state(4) == LOW) {
    if (setting == 2) {
      delay(ButtonDelay);
      btnDOWN++;
      lcd.clear();
    }
  }
  switch (btnDOWN)
  {
    case 1:
      {
        InternalScreen1();
        break;
      }
    case 2:
      {
        InternalScreen2();
        break;
      }
    case 3:
      {
        InternalScreen3();
        break;
      }
    case 4:
      {
        btnDOWN = 1;
        break;
      }

  }

}
void welcome()
{
  lcd.setCursor(5, 0);
  lcd.print("   KSP  ");
  lcd.setCursor(2, 1);
  lcd.print("   Evaporative  ");
  lcd.setCursor(0, 2);
  lcd.print("   Cooling Systems  ");
  delay(1000);
}
void mainpage()
{
  ScreenNumber = 1;
  DateTime now = RTC.now();
  Serial.print(now.month(), DEC);
  Serial.print('/');
  Serial.print(now.day(), DEC);
  Serial.print('/');
  Serial.print(now.year(), DEC);
  Serial.print(' ');
  Serial.print(now.hour(), DEC);
  Serial.print(':');
  Serial.print(now.minute(), DEC);
  Serial.print(':');
  Serial.print(now.second(), DEC);
  Serial.println();
  //////////////////////////////////
  lcd.setCursor(0, 0);
  lcd.print("Temp=");
  lcd.setCursor(6, 0);
  lcd.print(int(temperature));
  lcd.setCursor(8, 0);
  lcd.print("C");
  lcd.setCursor(0, 1);
  lcd.print("Hum.=");
  lcd.setCursor(6, 1);
  lcd.print(int(humidity));
  lcd.setCursor(8, 1);
  lcd.print("%");
  lcd.setCursor(0, 3);
  lcd.print(now.day(), DEC);
  lcd.setCursor(2, 3);
  lcd.print("/");
  lcd.print(now.month(), DEC);
  lcd.setCursor(4, 3);
  lcd.print("/");
  lcd.print(now.year(), DEC);
  lcd.setCursor(10, 0);
  lcd.print("Temp1=");
  lcd.setCursor(17, 0);
  lcd.print(int(t1));
  lcd.setCursor(19, 0);
  lcd.print("C");
  lcd.setCursor(10, 1);
  lcd.print("Temp2=");
  lcd.setCursor(17, 1);
  lcd.print(int(tt));
  lcd.setCursor(19, 1);
  lcd.print("C");
  lcd.setCursor(10, 3);
  lcd.print("Day.=");
  lcd.setCursor(15, 3);
  lcd.print(now.day(), DEC);
}
void displayValues() {
  // print out all 16 buttons
  for (int i = 0; i < shift.getDataWidth(); i++)
    Serial.print( shift.state(i) ); // get state of button i
  Serial.println();
}
//Internal Menu Start--------------------------
void InternalScreen0()
{
  isMainMenu = false;
  ScreenNumber = 10;
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print(F("------Setting------"));
  lcd.setCursor(0, 1);
  lcd.print(F("-> Mode            "));
  lcd.setCursor(0, 2);
  lcd.print(F("   Sensor adjust   "));
  lcd.setCursor(0, 3);
  lcd.print(F("   Output Setup    "));

  //For Debug
  Serial.print(F("InternalScreen0 -> "));
  Serial.println(ScreenNumber);
}

void InternalScreen1()
{
  isMainMenu = false;
  ScreenNumber = 11;
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print(F("------Setting------"));
  lcd.setCursor(0, 1);
  lcd.print(F("   Mode            "));
  lcd.setCursor(0, 2);
  lcd.print(F("-> Sensor adjust   "));
  lcd.setCursor(0, 3);
  lcd.print(F("   Output Setup    "));

  //For Debug
  Serial.print(F("InternalScreen1 -> "));
  Serial.println(ScreenNumber);
}

void InternalScreen2()
{
  isMainMenu = false;
  ScreenNumber = 12;
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print(F("------Setting------"));
  lcd.setCursor(0, 1);
  lcd.print(F("   Mode            "));
  lcd.setCursor(0, 2);
  lcd.print(F("   Sensor adjust   "));
  lcd.setCursor(0, 3);
  lcd.print(F("-> Output Setup    "));

  //For Debug
  Serial.print(F("InternalScreen2 -> "));
  Serial.println(ScreenNumber);
}
void InternalScreen3()
{
  isMainMenu = false;
  ScreenNumber = 13;
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print(F("------Setting------"));
  lcd.setCursor(0, 1);
  lcd.print(F("   Sensor adjust  "));
  lcd.setCursor(0, 2);
  lcd.print(F("   Output Setup   "));
  lcd.setCursor(0, 3);
  lcd.print(F("-> Date/Time      "));

  //For Debug
  Serial.print(F("InternalScreen3 -> "));
  Serial.println(ScreenNumber);
}
//Internal Menu end--------------------------

พอผมกดปุ่ม ตั้งค่า คือขา 3 แล้ว พอกดปุ่ม ลงแล้วมัน กระพริบอะครับ

ถ่ายวีดีโอสั่นๆ มาดูหน่อยครับ

ตอนนี้หายกระพริบแล้วครับผม

#include <LiquidCrystal_I2C.h>
#include <Wire.h>
#include <ShiftIn.h>
#include <Adafruit_AM2315.h>
#include "RTClib.h"
ShiftIn<2> shift;
RTC_DS1307 RTC;
LiquidCrystal_I2C lcd(0x38, 20, 4);
Adafruit_AM2315 am2315;
#define THERMISTORNOMINAL 10000
#define TEMPERATURENOMINAL 25
#define NUMSAMPLES 5
#define BCOEFFICIENT 3950
#define SERIESRESISTOR 10000
unsigned int ScreenNumber = 0;
float temperature, humidity;
float t1;
float tt;
int buttonMode = 3;
int b_mode;
int mode = 0;
int buttonOk = 4;
int b_ok = 0;
int ok = 0;

void setup() {
  pinMode(buttonMode  , INPUT);
  pinMode(buttonOk  , INPUT);
  Serial.begin(9600);
  shift.begin(8, 0, 11, 12);
  RTC.begin();
  am2315.begin();
  lcd.begin();
  welcome();
  lcd.clear();
}

void loop() {
  b_mode = digitalRead(buttonMode);
  b_ok = digitalRead(buttonOk);
  uint16_t samples1[NUMSAMPLES];
  uint16_t samples2[NUMSAMPLES];
  float average1;
  float average2;
  int i = 0;
  float factor = 7.5;

  if (! am2315.readTemperatureAndHumidity(&temperature, &humidity)) {
    return;
  }
  for (i = 0; i < NUMSAMPLES; i++) {
    samples1[i] = analogRead(A0);
    samples2[i] = analogRead(A1);
  }

  average1 = 0;
  average2 = 0;

  for (i = 0; i < NUMSAMPLES; i++) {
    average1 += samples1[i];
    average2 += samples2[i];
  }
  average1 /= NUMSAMPLES;
  average1 = 1023 / average1 - 1;
  average1 = SERIESRESISTOR / average1;

  average2 /= NUMSAMPLES;
  average2 = 1023 / average2 - 1;
  average2 = SERIESRESISTOR / average2;

  t1 = average1 / THERMISTORNOMINAL;          // (R/Ro)
  t1 = log(t1);                               // ln(R/Ro)
  t1 /= BCOEFFICIENT;                         // 1/B * ln(R/Ro)
  t1 += 1.0 / (TEMPERATURENOMINAL + 273.15); // + (1/To)
  t1 = 1.0 / t1;                              // Invert
  t1 -= 273.15;                               // convert to C

  tt = average2 / THERMISTORNOMINAL;          // (R/Ro)
  tt = log(tt);                               // ln(R/Ro)
  tt /= BCOEFFICIENT;                         // 1/B * ln(R/Ro)
  tt += 1.0 / (TEMPERATURENOMINAL + 273.15); // + (1/To)
  tt = 1.0 / tt;                              // Invert
  tt -= 273.15;

  Serial.print(t1); Serial.print(":*C Temp1 ");
  Serial.println();
  Serial.print(tt); Serial.print(":*C Temp2 ");
  Serial.println();
  if (shift.update())
    displayValues();
  Serial.print("Temp *C: "); Serial.println(int(temperature));
  Serial.print("Hum %: "); Serial.println(int(humidity));
  if (shift.update())
    displayValues();
  if (mode == 0) {
    mainpage();
  }
  if (b_ok == LOW) {
    lcd.clear();
    mode = 0;
  }

  if (b_mode == LOW) {
    mode = 1;
    switch (mode)
    {
      case 1:
        {
          lcd.clear();
          mode = 2;
          InternalScreen0();
          break;
        }
    }
  }
  if (shift.state(4) == LOW) {
    if (mode == 2) {
      switch (ScreenNumber)
      {
        case 10:
          {
            lcd.clear();
            InternalScreen1();
            break;
          }
        case 11:
          {
            lcd.clear();
            InternalScreen2();
            break;
          }
        case 12:
          {
            lcd.clear();
            InternalScreen3();
            break;
          }
        case 13:
          {
            lcd.clear();
            InternalScreen4();
            break;
          }
        case 14:
          {
            lcd.clear();
            InternalScreen0();
            break;
          }
        case 15:
          {
            lcd.clear();
            ModeScreen1();
            break;
          }
        case 16:
          {
            lcd.clear();
            ModeScreen0();
            break;
          }
      }
    }
  }
  if (shift.state(3) == LOW) {
    if (mode == 2) {
      switch (ScreenNumber)
      {
        case 10:
          {
            lcd.clear();
            InternalScreen4();
            break;
          }
        case 11:
          {
            lcd.clear();
            InternalScreen0();
            break;
          }
        case 12:
          {
            lcd.clear();
            InternalScreen1();
            break;
          }
        case 13:
          {
            lcd.clear();
            InternalScreen2();
            break;
          }
        case 14:
          {
            lcd.clear();
            InternalScreen3();
            break;
          }
        case 15:
          {
            lcd.clear();
            ModeScreen1();
            break;
          }
        case 16:
          {
            lcd.clear();
            ModeScreen0();
            break;
          }
      }
    }
  }
  if (shift.state(5) == LOW) {
    if (mode == 2) {
      switch (ScreenNumber)
      {
        case 10:
          {
            lcd.clear();
            ModeScreen0();
            break;
          }
        case 14:
          {
            lcd.clear();
            mode = 0;
            break;
          }
      }
    }
  }
  if (shift.state(6) == LOW) {
    if (mode == 2) {
    }
  }
}
void displayValues() {
  // print out all 16 buttons
  for (int i = 0; i < shift.getDataWidth(); i++)
    Serial.print( shift.state(i) ); // get state of button i
  Serial.println();
}
void welcome()
{
  lcd.setCursor(5, 0);
  lcd.print("   KSP  ");
  lcd.setCursor(2, 1);
  lcd.print("   Evaporative  ");
  lcd.setCursor(0, 2);
  lcd.print("   Cooling Systems  ");
  delay(1000);
}
void mainpage()
{
  DateTime now = RTC.now();
  Serial.print(now.month(), DEC);
  Serial.print('/');
  Serial.print(now.day(), DEC);
  Serial.print('/');
  Serial.print(now.year(), DEC);
  Serial.print(' ');
  Serial.print(now.hour(), DEC);
  Serial.print(':');
  Serial.print(now.minute(), DEC);
  Serial.print(':');
  Serial.print(now.second(), DEC);
  Serial.println();
  //////////////////////////////////
  lcd.setCursor(0, 0);
  lcd.print("Temp=");
  lcd.setCursor(6, 0);
  lcd.print(int(temperature));
  lcd.setCursor(8, 0);
  lcd.print("C");
  lcd.setCursor(0, 1);
  lcd.print("Hum.=");
  lcd.setCursor(6, 1);
  lcd.print(int(humidity));
  lcd.setCursor(8, 1);
  lcd.print("%");
  lcd.setCursor(0, 3);
  lcd.print(now.day(), DEC);
  lcd.setCursor(2, 3);
  lcd.print("/");
  lcd.print(now.month(), DEC);
  lcd.setCursor(4, 3);
  lcd.print("/");
  lcd.print(now.year(), DEC);
  lcd.setCursor(10, 0);
  lcd.print("Temp1=");
  lcd.setCursor(17, 0);
  lcd.print(int(t1));
  lcd.setCursor(19, 0);
  lcd.print("C");
  lcd.setCursor(10, 1);
  lcd.print("Temp2=");
  lcd.setCursor(17, 1);
  lcd.print(int(tt));
  lcd.setCursor(19, 1);
  lcd.print("C");
  lcd.setCursor(10, 3);
  lcd.print("Day.=");
  lcd.setCursor(15, 3);
  lcd.print(now.day(), DEC);
}
void InternalScreen0()
{
  ScreenNumber = 10;
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print(F("------Setting------"));
  lcd.setCursor(0, 1);
  lcd.print(F("-> 1.Mode           "));
  lcd.setCursor(0, 2);
  lcd.print(F("   2.Sensor adjust  "));
  lcd.setCursor(0, 3);
  lcd.print(F("   3.Output Setup   "));

  //For Debug
  Serial.print(F("InternalScreen0 -> "));
  Serial.println(ScreenNumber);
}

void InternalScreen1()
{
  ScreenNumber = 11;
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print(F("------Setting------"));
  lcd.setCursor(0, 1);
  lcd.print(F("   1.Mode           "));
  lcd.setCursor(0, 2);
  lcd.print(F("-> 2.Sensor adjust  "));
  lcd.setCursor(0, 3);
  lcd.print(F("   3.Output Setup   "));

  //For Debug
  Serial.print(F("InternalScreen1 -> "));
  Serial.println(ScreenNumber);
}

void InternalScreen2()
{
  ScreenNumber = 12;
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print(F("------Setting------"));
  lcd.setCursor(0, 1);
  lcd.print(F("   1.Mode           "));
  lcd.setCursor(0, 2);
  lcd.print(F("   2.Sensor adjust  "));
  lcd.setCursor(0, 3);
  lcd.print(F("-> 3.Output Setup   "));

  //For Debug
  Serial.print(F("InternalScreen2 -> "));
  Serial.println(ScreenNumber);
}
void InternalScreen3()
{
  ScreenNumber = 13;
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print(F("------Setting------"));
  lcd.setCursor(0, 1);
  lcd.print(F("   2.Sensor adjust "));
  lcd.setCursor(0, 2);
  lcd.print(F("   3.Output Setup  "));
  lcd.setCursor(0, 3);
  lcd.print(F("-> 4.Date/Time     "));

  //For Debug
  Serial.print(F("InternalScreen3 -> "));
  Serial.println(ScreenNumber);
}
void InternalScreen4()
{
  ScreenNumber = 14;
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print(F("------Setting------"));
  lcd.setCursor(0, 1);
  lcd.print(F("   3.Output Setup "));
  lcd.setCursor(0, 2);
  lcd.print(F("   4.Date/Time    "));
  lcd.setCursor(0, 3);
  lcd.print(F("-> 5.Exit         "));
  //For Debug
  Serial.print(F("InternalScreen4 -> "));
  Serial.println(ScreenNumber);
}
void ModeScreen0()
{
  ScreenNumber = 15;
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print(F("-------Mode-------"));
  lcd.setCursor(0, 1);
  lcd.print(F("-> 1.Temp of state"));
  lcd.setCursor(0, 2);
  lcd.print(F("   2.Hum of state"));
  //For Debug
  Serial.print(F("InternalScreen5 -> "));
  Serial.println(ScreenNumber);
}
void ModeScreen1()
{
  ScreenNumber = 16;
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print(F("-------Mode-------"));
  lcd.setCursor(0, 1);
  lcd.print(F("   1.Temp of state"));
  lcd.setCursor(0, 2);
  lcd.print(F("-> 2.Hum of state"));
  //For Debug
  Serial.print(F("InternalScreen6 -> "));
  Serial.println(ScreenNumber);
}
//Internal Menu end--------------------------
1 Like

ตอนนี้กำลังหาวิธีตั้ง เวลา RTC หลายๆเวลาผ่านหน้าจอ LCD อะครับ

RTC เขียนยังไงถึงเรียก ฝั่งชั้น RTC ได้ทุกหน้าอะครับ ตอนนี้ผมเรียกออกมาแล้วเวลามันไม่เดินมันต้องอยู่ในลูปอะครับ

คือยังไงหรอครับยกตัวอย่างหน่อย

void datetime()
{
  DateTime now = RTC.now();
  ScreenNumber = 24;
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print(F("------DateTime------"));
  //For Debug
  Serial.print(F("InternalScreen4 -> "));
  Serial.println(ScreenNumber);
}

แบบนี้อะครับ ผมอยากให้มันวนลูป หรือควรใช่ interrupt ในการใช้กับ rtc

ให้มันทำงาน ทุกๆ กี่วินาที แล้วแต่เราจะตั้งงี้อะหรือครับ เราก็ใส่ไปใน void loop() ไม่ได้หรอ

ผมใช้กับ interrupt แล้วครับให้มันทำงานทุกๆ 1 วิ