0

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 imagining 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 a snippet 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.

closed as unclear what you're asking by per1234, VE7JRO, Gerben, sempaiscuba, Greenonline Dec 3 '18 at 0:59

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • what is "to generate an input"? output is generated. input is read. – Juraj Dec 2 '18 at 6:26
  • @Juraj Hey Juraj! Thanks for taking the time to respond. To clarify: it would be the output generated. – Darkseid305 Dec 2 '18 at 7:02
  • 1
    post real code and describe what is wrong – Juraj Dec 2 '18 at 9:49
  • In your if statement set a flag and a timestamp with the millis() function. Also in the main loop write code like in the BlinkWithoutDelay example, which gets activated by the flag. In side it, you can reset the flag – chrisl Dec 2 '18 at 9:59
1

A standard way to do this is to connect a digital i/o pin via a (normally open) push button to ground. Internally in the Arduino a pullup resistor can be activated to keep the pin on a high level when de button is open. For example when pin #8 is used: pinMode(8, INPUT_PULLUP). The program watches the state of the pin to detect whether the button has been pushed. An extensive tutorial about using switches for input to microcomputers you can find here: http://www.gammon.com.au/forum/?id=11955

Be sure to familiarize yourself with a phenomenon called "contact bouncing": when the button is pressed or released the contacts don't open or close immediately but go through a series of rapid open/close/open/etc. states. The best information I know about how to handle this you can find here: http://www.ganssle.com/debouncing.htm

Not the answer you're looking for? Browse other questions tagged or ask your own question.