How to create objects with their own variables? So i created a class and when i created objects and use them, they seem to share their variables between each other ( the currentReading, previousReading and the time variable). how can i create objects that have their own variables so that type of conflict cant happen?

code : ( read the buttons and print them in the lcd screen)

#include &lt;LiquidCrystal.h&gt;

LiquidCrystal lcd(6, 5, 3, 2, 1, 0);


class button {
  public:
    void SetupButton(int pino);
    int Read();

  private:
    int _pin;
};

void button::SetupButton(int pin) {
  pinMode(pin, INPUT_PULLUP);
  _pin = pin;

}


int button::Read() {
  static boolean currentReading, previousReading = 1;
  static unsigned long time;




  currentReading = digitalRead(_pin);// reading
  if (previousReading - currentReading  == 1) { // when reading gos from 1 to 0
    time = millis();
  }

  if (currentReading - previousReading == 1 &amp;&amp; (50 &lt; (millis() - time) &lt; 500)) {     // when reading gos back to 1 before 500ms
    previousReading = currentReading;
    return 1;
  }

  if (3000 &gt; (millis() - time) &amp;&amp; (millis() - time) &gt; 500 &amp;&amp; !currentReading) { // when reading keeps in 0 after 500ms
    previousReading = currentReading;
    return 2;
  }

  if ((millis() - time) &gt; 3000 &amp;&amp; !currentReading) { // // when reading keeps in 0 after 3000ms
    previousReading = currentReading;
    return  3;
  }

  previousReading = currentReading; // current reading becomes the previous

  return 0;
}


button up;
button down;


void setup() {
  lcd.begin(16, 2);
  up.SetupButton(A0);
  down.SetupButton(A1);

}
void loop() {


  lcd.setCursor(0, 0);
  lcd.print(up.Read());
  lcd.print(down.Read());


}


ps :  i already know how to do this without using classes but doing it with classes makes the code much cleaner so i am trying to achieve this
I was tempted to re-write your code (I am quite rusty on c++), but you may be better to start with an existing class. 

There is a Button class on the Arduino site. See https://playground.arduino.cc/Code/Button

You could use this or study to see a more usual c++ implementation and adapt your code.

Virtually ALL c++ classes include a constructor. I would use instead of SetupButton

void button::button(int pin) {
  this-&gt;_pin=pin;
  pinMode(pin, INPUT_PULLUP);
}


and add uint8_t previousReading; and unsigned long time; to your class as private variables.