Show Posts
Pages: [1]
1  Using Arduino / Project Guidance / Re: trouble with timestamps on: April 09, 2011, 07:48:12 am
yes i have pull downs however even if i put a much larger amount for instance   " if((TS1 >500) && (TS2 >500)"

even the slightest touch on the button gives exactly the same results as before.
2  Using Arduino / Project Guidance / Re: trouble with timestamps on: April 09, 2011, 07:36:23 am
Ive altered it and am still getting the same result, at present pushing "button 1" will light the led regardless of the other button for what ever period is set in "(abs(TS1-TS2) < 1000))"

pressing button 2 does nothing at all

any ideas?

Quote
#define buttonPin1 1
#define buttonPin2 2
#define ledPin1  9

int button1 = 0;
int button2 = 0;

unsigned long TS1 = 0;
unsigned long TS2 = 0;

void setup(){
 
  pinMode(buttonPin1, INPUT);
  pinMode(buttonPin2, INPUT);
  pinMode(ledPin1, OUTPUT);
}

void loop(){
 
  button1 = digitalRead(buttonPin1);
  button2 = digitalRead(buttonPin2);
 
 if(button1 == HIGH){
  TS1 = millis();
 }
 if(button2 ==HIGH){
   TS2 = millis();
 }
 
 if((TS1 != 0) && (TS2 != 0) && (abs(TS1-TS2) < 1000)){
   digitalWrite(ledPin1, HIGH);
 }
 else{
   digitalWrite(ledPin1, LOW);
 }
 
}
3  Using Arduino / Project Guidance / trouble with timestamps on: April 09, 2011, 06:22:40 am
so  I started a project yesterday in which i am trying to get an event to happen when 2 buttons are pressed within a certain time of each other ie. button 1 is pushed and within 2 seconds button 2 is pushed and then an LED lights up.

I got a bit of help yesterday but am still struggling to get it to work any help pointing out where i am going wrong would be greatly appreciated.

Code:
const int buttonPin1 = 1;
const int buttonPin2 = 2;
const int ledPin1 = 9;

unsigned long TS1 = 0;
unsigned long TS2 = 0;

void setup(){
  pinMode(buttonPin1, INPUT);
  pinMode(buttonPin2, INPUT);
  pinMode(ledPin1, OUTPUT);
  pinMode(ledPin2,OUTPUT);
  pinMode(ledPin3,OUTPUT);
}

void loop(){
 if(buttonPin1 == HIGH){
  TS1 = millis();
 }
 if(buttonPin2 ==HIGH){
   TS2 = millis();
 }
 
 if((TS1 != 0) && (TS2 != 0) && (abs(TS1-TS2) < 2000)){
   digitalWrite(ledPin1, HIGH);
 }
 else{
   digitalWrite(ledPin1, LOW);
 }
 
}
4  Using Arduino / Project Guidance / Re: output dependant on 2 inputs. on: April 08, 2011, 09:57:53 am
Had a quick go and got stuck with "< 2seconds"

sorry all of this is very new to me. is this getting closer to what i need?

Code:
int buttonPin1 = 1;
int buttonPin2 = 2;
int ledPin1 = 9;
int ledPin2 = 10;


int buttonState1;
int buttonState2;

unsigned long TS1 = 0;
unsigned long TS2 = 0;

void setup(){


  pinMode(buttonPin1, INPUT);
  pinMode(buttonPin2, INPUT);
  pinMode(ledPin1, OUTPUT);
  pinMode(ledPin2, OUTPUT);
}

void loop(){

 buttonState1 = digitalRead(buttonPin1);
buttonState2 = digitalRead(buttonPin2);
 
if (buttonState1 ==HIGH){
  TS1 = millis();
}

if (buttonState2 == HIGH){
  TS2 = millis();
}

if ((TS1 != 0) && (TS2 != 0) && (abs(TS1 - TS2) < 2seconds))
{
    digitalWrite(ledPin1, HIGH);
  }
  else{
    digitalWrite(ledPin1, LOW);
}

}
5  Using Arduino / Project Guidance / output dependant on 2 inputs. on: April 08, 2011, 09:15:59 am
I am trying to put together a project that when both a microphone and a pressure sensor both give a peak reading a output is triggered however at present i am experimenting with simple push buttons before using analog inputs.

what I am trying to achieve is that when both buttons are pressed or pressed within a given time of each other (ie. one button is pushed and the other is pushed within 2 seconds) that an event is triggered.

any help at all getting this to work with at least the buttons would be greatly appreciated.

so far this is what i have, but have been having trouble getting the two buttons to operate independently, the LedPins are currently just being used for testing purposes. I havnt got this far yet but the intention was that when both counters = 1 they would trigger an event.

int buttonPin1 = 1;
int buttonPin2 = 2;
int ledPin1 = 9;
int ledPin2 = 10;

int counter1 = 0; //using a counter to determine button state
int counter2 = 0;

int buttonState1;
int buttonState2;

void setup(){


  pinMode(buttonPin1, INPUT);
  pinMode(buttonPin2, INPUT);
  pinMode(ledPin1, OUTPUT);
  pinMode(ledPin2, OUTPUT);
}

void loop(){
  buttonState1 = digitalRead(buttonPin1);
  buttonState2 = digitalRead(buttonPin2);

  if (buttonState1 == HIGH){
    counter1++;
    if (counter1 >1){
      counter1 = 0;
    }
  }
  if(buttonState2 == HIGH){
    counter2++;
    if (counter2 >1){
      counter2 = 0;
    }
  }
if (counter1 == 1){
    digitalWrite(ledPin1, HIGH);
  }
  else if(counter1 != 1){
    digitalWrite(ledPin1, LOW);
  }
  if (counter2 == 1){
    digitalWrite(ledPin2, HIGH);
  }
  else if(counter2 != 1){
    digitalWrite(ledPin2, LOW);
  }
if(counter1 ==1){     //this part had the intention of resetting each counter to 0 after 1 second.
  delay(1000);
  counter1--;
}
if(counter2 ==1){
  delay(1000);
  counter2--;
}

}
Pages: [1]