Go Down

Topic: logic help (Read 1 time) previous topic - next topic


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: [Select]
int buttonState;
boolean occuring;
int oldButtonState;

void setup() {
  pinMode(7, INPUT);

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

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

  oldButtonState = buttonState;


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.


i'm using one of these buttons:


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:

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

thanks so much for all the help


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


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.



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.


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.

Go Up