Button gets executed by my program I believe? First project.

Hello everyone,

This is my first project. And I've created what I believe is the basics I need to get going for my goal with my Arduino. Yet I stumble uppon my first annoyance already.

I've put my code online at Pastebin.

The issue I seem to be having, the loop at line 82 also updates my LCD with the text 'Button 1 pressed' found at line 102. Could anyone clarify this? I'm pretty sure the LCD even updates at the interval the random number is generated.

Sidenote: Seeing this is my first project and I have rather very limited knowledge of any programming language feel free to give constructive feedback if I could write the code better.

Thank you for the support and hello Arduino community.
I'm not English as a native so excuse me for any errors above.

Happy Holidays while we're at it!

Use CTRL T to format your code.
Attach your sketch ‘here’ between code tags
[code]Paste your sketch here[/code]

Edit: Issue is solved, Pin 1 is used by RS232. Makes perfect sense now that I think of it. The RS232 TXD/RXD is also a voltage and this triggered the button. Thank you, have a nice newyears eve.

Hello,

I figured it was too big, sorry. The source file attacement didn’t work either somehow.
But here goes, thank you.

//Load and use pre-defined LCD system
#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
//create integers used
int Status = 1;
int RandomNr;
int Position;
int Move;
int RedLed = 12;
int GreenLed = 11;
int Button1 = 1;
int Button2 = 2;
int ZeroSetting = 0;
int LCDLight = 6;
int MaxSetting = 0;
int RandomMode = 0;
int MinRandom = 1000;
int MaxRandom = 4000;
unsigned long PreviousMls = 0;
const long Interval = 2000;
String vers = "    Version 0.1";


void setup() {
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  Serial.begin(9600);
  // Declare pinmode's
  pinMode(Button1, INPUT_PULLUP);
  pinMode(Button2, INPUT_PULLUP);
  pinMode(RedLed, OUTPUT);
  pinMode(GreenLed, OUTPUT);
  pinMode(LCDLight, OUTPUT);
  analogWrite(LCDLight, 140); // brightness setting for LCD, 0-255 (0-5v)
  // Welcome user on the LCD
  lcd.print(" #ScaleSimTool#");
  lcd.setCursor(0, 1);
  lcd.print(vers);
  delay(500);
  lcd.clear();
  lcd.print(" *ScaleSimTool*");
  lcd.setCursor(0, 1);
  lcd.print(vers);
  delay(500);
  lcd.clear();
  lcd.print(" /ScaleSimTool/");
  lcd.setCursor(0, 1);
  lcd.print(vers);
  delay(500);
  lcd.clear();
  lcd.print(" #ScaleSimTool#");
  lcd.setCursor(0, 1);
  lcd.print(vers);
  delay(500);
  lcd.clear();
  lcd.print(" *ScaleSimTool*");
  lcd.setCursor(0, 1);
  lcd.print(vers);
  delay(500);
  lcd.clear();
  lcd.print(" /ScaleSimTool/");
  lcd.setCursor(0, 1);
  lcd.print(vers);
  delay(500);
  lcd.clear();
  lcd.print(".");
  delay(500);
  lcd.clear();
  lcd.print("...");
  delay(500);
  lcd.clear();
  lcd.print("......");
  delay(500);
  lcd.clear();
  lcd.print("Starting Up!");
  delay(1500);
  lcd.clear();
  }

void loop() {
  unsigned long CurrentMls = millis(); // update the value to be used as a timer. Delay makes the 'stop' buttons not possible.
  if ( (RandomMode == 1) && (Status == 1) && (ZeroSetting == 0) && (MaxSetting == 0)) { //checking requirements if it's ok to do random weighings 
    if (CurrentMls - PreviousMls >= Interval) { //using an if statement to bypass the delay
    // If Status & Random is on, but zero/max is off
    Serial.println("Generating random values as test"); //using the serial tool as debug
    RandomNr = random(MinRandom - MaxRandom); // Update the integer with a random number, Min&Max can be user defined
    PreviousMls = CurrentMls; //update Previous Milisecond integer to be used in the timer tool
    Serial.println(RandomNr); 
    }
    
  }
  // Detect & Print is either button 1 or 2 is pressed
  // If status = 1 button's wont be checked AND if scale is not being set to zero OR max currently
  if ( (Status == 1) && (ZeroSetting == 0) && (MaxSetting == 0 )) {
  if (digitalRead(Button1) == LOW) { 
    lcd.print("Button 1 pressed");
    delay(600);
    lcd.clear();
    RandomMode = 1;
  }
    if (digitalRead(Button2) == LOW) { 
    lcd.print("Button 2 pressed");
    delay(600);
    lcd.clear();
    RandomMode = 0;
  }
  }

}

Yes, try to avoid D0 and D1 as these are used for serial communications.

Welcome to the group.