help with very simple code! please

hey there , im new to arduino and have built myself an intervalometer for my canon 1000d the hardware all works m it consists of a standard 16 pin 2 line lcd , 1 pushbutton, 1 toggle switch, and the lead to the camera , (ground , focus and photo) the setup works just i cant get the code i want to work , im too much of a noob to figure out whats wrong lol.

basically i wnt it so that when i turn on the device ( i have a toggle switch attached to a 9v battery) it says " inter blah blah by blah blah" and then after 3 seconds checks the status of the toggle switch , if its low then read the status of the pushbutton ,

when pushed the pushbutton will send a pulse down the lead (focus and photo) and then on the lcd display “single mode:” and then a count , of how many times it has been pressed (thats simple). if the toggle switch is high i want the lcd to pulse the lead every 15 seconds ( interval i need for timelapse) and display the count and also “time-lapse mode” when the count reaches 240 i want the code to stop and display done.

im having 2 problems with my code , when the lcd is set to timrlapse mode , the count is only displayed when the lead is pulsed, for that split second, i want it to stay on screen , but i feel tht because the code is looping every 15 seconds this cant be done.

also the code is not reading the state of the toggle switch, it just jumps straight into timelapse mode. ill post the code below , any help would be fantastic , its drivimg me insane , ive written it so many times gahhh.

#include <LiquidCrystal.h>
const int buttonPin = 4;     // the number of the pushbutton pin
const int ledPin =  13;
const int photo = 6;
const int focus = 5;
const int button2 = 3;
// the number of the LED pin

// variables will change:
int buttonstate = 0;
int buttonstate2 = 0;
int Val = 1;
int valt = 0;

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

void setup() {
  // set up the LCD's number of rows and columns:
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("Intvlmtr v1.0");
  lcd.setCursor(0, 1);
  lcd.print("By: Scott Meades");
  pinMode(ledPin, OUTPUT);
pinMode(photo, OUTPUT);
pinMode(focus, OUTPUT);
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);
 pinMode(button2, INPUT);
 delay(3000);

}

void loop()
{
  buttonstate = digitalRead(buttonPin);
 buttonstate2 = digitalRead(button2);

 if (buttonstate2 = HIGH);
 {
 lcd.begin(16, 2);
 lcd.print("Time-lapse mode");
 delay(15000);
 lcd.setCursor(2, 1);
 lcd.print(valt++);
 digitalWrite(focus, HIGH);
 digitalWrite(photo, HIGH);
 digitalWrite(ledPin, HIGH);

 digitalWrite(focus, LOW);
 digitalWrite(photo, LOW);
 digitalWrite(ledPin, LOW);


 }
 if (buttonstate2 = LOW);
 { if (buttonstate = HIGH);
 {digitalWrite(ledPin, HIGH);
    digitalWrite(photo, HIGH);
    digitalWrite(focus, HIGH);
    delay(1000);
    lcd.clear();
    
  lcd.print("Single mode:");
  lcd.print(Val++);}
  if (buttonstate = LOW);
  {digitalWrite(ledPin, LOW);
   digitalWrite(photo, LOW);
    digitalWrite(focus, LOW);
  }

 }

 if (valt >= 239);
 { lcd.clear();
 lcd.begin(16, 2);
 lcd.print("Done!");
 }
}

Please do not cross-post.

i wasnt sure what catagory to post this under. i really really need help

You can probably start by removing the semi-colon found at the end of everyone of your ‘if’ statements.

Next you’ll need to change the “=”, an assignment, in each of your if statements to “==”, a comparison.

#include <LiquidCrystal.h>

const int buttonPin = 4;     // the number of the pushbutton pin
const int ledPin =  13;
const int photo = 6;
const int focus = 5;
const int button2 = 3;
// the number of the LED pin

// variables will change:
bool done;
int buttonstate = 0;
int buttonstate2 = 0;
int Val = 1;
int valt = 0;

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

void setup()
{
    done = false;

    // set up the LCD's number of rows and columns:
    lcd.begin(16, 2);

    // Print a message to the LCD.
    lcd.print("Intvlmtr v1.0");
    lcd.setCursor(0, 1);
    lcd.print("By: Scott Meades");

    pinMode(ledPin, OUTPUT);
    pinMode(photo, OUTPUT);
    pinMode(focus, OUTPUT);

    // initialize the pushbutton pin as an input:
    pinMode(buttonPin, INPUT);
    pinMode(button2, INPUT);
    delay(3000);
}

void loop()
{
    if ( done ) return;

    buttonstate = digitalRead(buttonPin);
    buttonstate2 = digitalRead(button2);
    
    if ( buttonstate2 == HIGH )
    {
        lcd.begin(16, 2);
        lcd.print("Time-lapse mode");

        delay(15000);

        lcd.setCursor(2, 1);
        lcd.print(valt++);

        digitalWrite(focus, HIGH);
        digitalWrite(photo, HIGH);
        digitalWrite(ledPin, HIGH);
        
        digitalWrite(focus, LOW);
        digitalWrite(photo, LOW);
        digitalWrite(ledPin, LOW);
    }

    if ( buttonstate2 == LOW )
    {
        if (buttonstate == HIGH)
        {
            digitalWrite(ledPin, HIGH);
            digitalWrite(photo, HIGH);
            digitalWrite(focus, HIGH);

            delay(1000);

            lcd.clear();
            lcd.print("Single mode:");
            lcd.print(Val++);
        }

        if ( buttonstate == LOW )
        {
            digitalWrite(ledPin, LOW);
            digitalWrite(photo, LOW);
            digitalWrite(focus, LOW);
        }
    }
    
    if ( valt >= 239 )
    {
        done = true;
        lcd.clear();
        lcd.begin(16, 2);
        lcd.print("Done!");
    }
}

thankyou sooo much , that works , few things tho that i still need to work out , in the last part where i say if its greater than 239 then make the pins low , how do i end the program? it keeps on pulsing the lead but shows "done!" how would i go about stopping the program.

also the led flashes when it pulses the lead , ( i set it tp do this,) but now with the new code the on board led is flashing very weakly, is this a problem??

I’m not sure what you mean by ‘done’ as ‘loop’ will continue to be called till power is interrupted.

You could have a global variable ‘bool done;’. Set the value to ‘done = false;’ in ‘setup’ and within the body of ‘if ( valt >= 239 )’ set ‘done = true;’ followed with ‘if ( done ) return;’ at the top of ‘loop’.

‘loop’ will be continue to be called but ‘done’ will have been set to ‘true’ and return immediately effectively doing nothing giving the appearance of having stopped.

Code changed above to reflect suggested changes.

thank you so much for helping me , my project is now complete and working exactly as i want it too :)