Start command??

I’m still in the early stages of my Arduino experience so please go easy on me if my questions seem somewhat dumb. I’m looking for a way to get my sketch to run the loop only after a momentary input to pin 12 on the Uno and a 2 second delay, a kind of start signal after which the sketch will run until it is reset and the start signal is applied again. Can anyone point me in the right direction please? Many thanks for any help you can give.

Bob

Kind of dangerous to ask how to make an addition to your sketch without including what you have. Use the code tags around your code so it shows in a scrolling window.

What is the momentary input to pin 12. Going high or going low? For delay, look up "delay".

Paul

Something like this, if your code is linear and it finish at the bottom of loop()

byte startSwitch = 12;

void setup() {
  pinMode (startSwitch, INPUT_PULLUP);
}

void loop() {
  while (digitalRead(startSwitch) == HIGH) {
    // just waiting here until pin 12 becomes LOW
  }
  delay (2000);

  // Put your code here

}

Use delays, since you're just starting. If you want to delay, do something like this:

.....
delay(2000); //2 seconds
//or
delay(1000*2); //This too would work

1000mS (milliseconds) = 1 second :slight_smile:

If you only want this behaviour once when the Arduino starts put it as the last thing in setup(). Something like this

void setup() {
   // your usual stuff
   while (digitalRead(12) == HIGH) { // assumes it will be low when pressed
   }
   delay(2000);
}

void loop() {
   // the rest of your code

}

...R

@ mancavebob

  1. I assume that you have connected a normally closed spring return push switch at DPin-12.

  2. The Pseudo Codes:

void setup()
{
     pinMode (12, INPUT_PULLUP); //DPin-12 is input with internal pull-up. LL is at the input of DPin-12      
     
}

void loop()
{

    while (bitRead(PINB, 5) == LOW)
        ;
     delay(2000);

     //--- insert your codes that the MCU will be executing until 'it is reset'. What have you wanted to
    // mean by saying 'it is reset'?
     
}

Hey thank you to everyone for the swift responses, particular thanks to Robin2 as your suggestion has worked perfectly. Loads to learn and I am getting there, Bob.