Button that gives an Output, Has a small delay --- then gives another

Hey everyone!

I'm pretty new to the Arduino scene, and my question will likely be solved simply by some more experienced fellows. I'm trying to create a code for a switch/ button that when you press it, it generates an output--- then waits (delays?) and produces another (after that set amount of time) before ending that transfer of information. Can any insight be shed on this? What would that look like? For example, the code that I am currently experimenting with is something like this :

if(buttonisPressed){
Function1 = 1; // Original output is issued

delay(1000); // Set time delay for the next output

Function2 = 1; // The second output follows suit after the set amount of delay time (only after one press, without a secondary)
}

This is the gist of the code I am using, but I haven't been able to get it to work.

Thanks so much for your help! Any advice at all would be greatly appreciated.

Why imagine? Type it in and give it a go.

-jim lee

@jimLee

Hey Jim! Thanks for taking the time to respond. I should have mentioned that with this code as earlier written, the desired effect does not happen. Upon the initial button press, no output is issued (instead there is a delay where all information transfer is cut off...it seems to be circumventing any other bit of code and jumping straight into the delay? I know that the delay code is definitely being considered --- the time in the delay() is always reflected in the break of information) and afterward there is no secondary output either.

Any recommendations? The problem-solving continues. I'd like to know if I'm even in the correct ballpark with using a delay() code as the route to manifest this behavior.

Remember, the goal is to press a button and for the output function to be activated ---- then after a small delay a secondary output is activated.

Thanks again!

Ok, look at what you wrote. :

This is the gist of the code I am using

This only means this is what you want. We need to see what you actually told the computer to do. Because your not telling it right.

And yes, delay() is like hitting a brick wall. Like using telephone poles to test your brakes. Beginners always get into trouble overusing delay().

-jim lee

Remember, the goal is to press a button and for the output function to be activated ---- then after a small delay a secondary output is activated.

The snippet that you posted should basically do that.

Post your complete code. And just in case, use code tags as describes onder point #7 here

Give a proper description of what the code is supposed to do and what it actually does.

If any additional hardware is connected to the Arduino, draw a schematic and post here. Which Arduino?

Hey guys! Thanks for responding.

jimLee:
Ok, look at what you wrote. :
This only means this is what you want. We need to see what you actually told the computer to do. Because your not telling it right.

Hey Jim, here’s a snippet of the code.

if(buttonisPressed){
  Function1 = 1;   // Original output is issued

  delay(1000);  // Set time delay for the next output

  Function2 = 1; // The second output follows suit after the set amount of delay time (only after one press, without a secondary)
}

When pressing the activating button, what happens is as follows:

It doesn’t give any initial output. All information from the Arduino comes to a halt for as long as whatever value is assigned in the delay() as soon as I press the button. It seems like it is jumping straight into the delay without outputting an initial function (which I want to take place before the delay) or outputting a secondary function which follows immediately after the delay.

Note: The Arduino in question in an Arduino Nano.

sterretje:
The snippet that you posted should basically do that.

Post your complete code. And just in case, use code tags as describes onder point #7 here

Give a proper description of what the code is supposed to do and what it actually does.

If any additional hardware is connected to the Arduino, draw a schematic and post here. Which Arduino?

See above. Thanks guys for your responses and your assistance!

Update: I’m well aware after doing some research on the subject that it may be harder than initially thought — and using delay() may not be the optimal answer. I’m open to any suggestions!

It would help if you posted the complete code that you have been asked for...several times.

E.g."Function1 = 1" does not run any function, it may set a variable but it then goes straight into the delay before anything can act on that variable. So if that's really what your code is doing then it explains why nothing runs before the delay.

Steve

Yeah, you still imagine you're telling the computer what you are thinking.

-jim lee