Pages: [1]   Go Down
Author Topic: help with very simple code! please  (Read 335 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 15
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#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!");
 }
}
 
« Last Edit: June 18, 2010, 10:02:19 pm by scooterboi039 » Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 289
Posts: 25702
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
if (buttonstate2 = HIGH)[glow];[/glow]
Would be one problem, repeated several times..
Logged

"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.

0
Offline Offline
Newbie
*
Karma: 0
Posts: 15
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Waterloo, Canada
Offline Offline
Full Member
***
Karma: 1
Posts: 242
Engineer
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Doesn't appear fixed...

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

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 289
Posts: 25702
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Doesn't appear fixed...

Cross-posted here:
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1276919281/0#0

Grrr.   >smiley-sad
Logged

"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.

Pages: [1]   Go Up
Jump to: