Pages: 1 [2]   Go Down
Author Topic: logic help  (Read 1047 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Full Member
***
Karma: 1
Posts: 142
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i took out the delays...now it just plays the if conditional on a loop until i press the button...when i press it, it stops, when i press it again, the loop starts again. i just want it to play a video and then stop and wait for another button press...i need the delays in there because there needs to be delays in between the arduino triggering the relays...

could this be because this library might not be for buttons that are either HIGH or LOW?

this is my other program i wrote...it works fine...it's just that while the video is playing i don't want it to register any button presses:

Code:
int buttonState;
boolean occuring;
int oldButtonState;

void setup() {
  Serial.begin(9600);
  pinMode(7, INPUT);
}

void loop() {
  buttonState = digitalRead(7);

  if (oldButtonState != buttonState) {
    Serial.println("Turn on");
    delay(200);
    Serial.println("Play");
    delay(2000);
    Serial.println("Turn off");
    delay(200);
    Serial.println("Wait for next press");
    delay(200);
  }

  oldButtonState = buttonState;
}
Logged

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 74
Posts: 7256
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I doubt your code works on the basis of lacking the necessary logic to recognize a press. But you said worked for you and you're ok with it so feel free to revert back. My code works fine for this button but I don't know why it didn't work for you. Did you hold the button or did you give it a quick press? I assume your button is tactile, not a click on click off. Maybe you have a click on click off button, which is why you keep getting this problems. Pictures please.
Logged


0
Offline Offline
Full Member
***
Karma: 1
Posts: 142
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i'm using one of these buttons:

http://www.radioshack.com/product/index.jsp?productId=2062544

it is a click button...pushes on and off. is this the problem?

i have it set up with a 1k pull up resistor...like on this page:
http://www.thebox.myzen.co.uk/Tutorial/Inputs_files/shapeimage_9.png

could it be because i'm using a 1k and not 3k like in the diagram?

thanks so much for all the help
Logged

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 74
Posts: 7256
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I guess I was right. That was a push on push off button. You should use this:

http://www.radioshack.com/product/index.jsp?productId=2062510

Read this for how to use internal pullup resistor. Your pullup is fine but you don't have to. Just connect button to pin 7 and gnd.

http://www.arduino.cc/en/Reference/DigitalWrite
Logged


0
Offline Offline
Full Member
***
Karma: 1
Posts: 142
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

bummer...well...i'm sort of visually attached to that button. this is for a visual art project. is there any way to write code to make this button behave like the other one? or is it pretty much impossible?

thanks again for all the help.
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 634
Posts: 34559
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
is there any way to write code to make this button behave like the other one
No but you can write the program to work off edges rather than levels.
The only thing you won't be able to do is to detect when the button is held down.
Logged

Pages: 1 [2]   Go Up
Jump to: