Why m turn to 0

#include <DS3231.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 16, 2);
DS3231 rtc(SDA, SCL);
Time t;
int buzzer = 7;
int ir = 5;
int m = 1;

class mode
{
  public :
  int mode1() 
  {
    lcd.setCursor(0,0);
    lcd.print("Time : ");
    lcd.print(rtc.getTimeStr());
  }
};
mode i;

void setup()
{
  pinMode(A0, INPUT);
  pinMode(A1, INPUT);
  pinMode(5, INPUT);
  Serial.begin(9600);
  lcd.begin();
  lcd.backlight();
  rtc.begin();
  rtc.setTime(21, 52, 0);
}

void loop()
{
  int x = analogRead(A0);
  if (x < 300)
  {
    m++;
    if (m > 4)
    {
      m = 1;
    }
    lcd.setCursor(0,0);
    lcd.print("mode : ");
    lcd.print(m);
    delay(1000);
    lcd.clear();
  }
  while (m = 1 && m > 300 && m <  700)
  {
    i.mode1();
  }
  Serial.println(m);
  delay(1000);
}

after run the serial monitor print out as 0

Oops

do you mean

while (m == 1 && x > 300 && x <  700)

?

you again!
i'm such an idiot

Be proud of yourself!
You make beginner errors (that experienced programmers may still make).
But you are trying. That is what matters!

1 Like

You seem to have started a second topic on the same subject

https://forum.arduino.cc/t/why-the-serial-print-out-0/1002374

Why ?

why i cant

Asking the same question multiple times wastes the time of those offering help. Did you not like the replies that you got here ?

but its not the same code

It's the same problem.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.