gfvalvo:
Always re-post the complete code after making changes.
Sorry
Here the one with "static":
// constants won't change. They're used here to set pin numbers:
const int buttonPin = 2; // the number of the pushbutton pin
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
void setup() {
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
lcd.begin(16,2);
}
void loop() {
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
int stock = 20;
static number = 1;
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (buttonState == HIGH) {
int plus = stock +number;
lcd.setCursor(0, 0);
lcd.print("Number: ");
lcd.print(plus);
}
}
And the one with global
// constants won't change. They're used here to set pin numbers:
const int buttonPin = 2; // the number of the pushbutton pin
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
number = 1;
void setup() {
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
lcd.begin(16,2);
}
void loop() {
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
int stock = 20;
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (buttonState == HIGH) {
int plus = stock +number;
lcd.setCursor(0, 0);
lcd.print("Number: ");
lcd.print(plus);
}
}