Go Down

Topic: help with very simple code! please (Read 358 times) previous topic - next topic

scott meades

Jun 19, 2010, 04:47 am Last Edit: Jun 19, 2010, 05:02 am by scooterboi039 Reason: 1
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.
Code: [Select]
#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!");
}
}


AWOL

Code: [Select]
if (buttonstate2 = HIGH)[glow];[/glow]
Would be one problem, repeated several times..
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

scott meades

thanks ,   that was one of the issues, ive since fixed up the code.

Mitch_CA

Doesn't appear fixed...

also "=" is assignment.  "==" is boolean comparison.

AWOL

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Go Up