-1

I am trying to create a program where the main code starts on the press of a button. I am using an Arduino Esplora, and I want to have the built-in LED be blue when I plug in the power until I press Switch 1 (or any of them), upon which the program starts. I have had no problem in making the main part of my program, but I would like to find a way to have my program by just pressing the button once, as currently it only works while I am holding the button down continuously - something that is not possible in the situation I am using it for. I can't use any components apart from the Esplora itself, which rules out the option of using switches, etc. which probably would have made my life easier 😂. I would appreciate any suggestions. I'm pretty new to Arduino, so I'm sorry if I ask any dumb questions, or don't understand some of the concepts you are talking about, but I'll try my best. Thank you!

1
  • 2
    please show us your code – chrisl Mar 10 '20 at 14:10
2

You could simulate the switch with the button by using a state variable that hold the state of the "switch". I don't know your code, so I can only give you an example on how to do that:

// the includes are here, if you need any

int flagActive = -1;

// ...

setup()
{
   // ... set the internal LED to blue
}

loop()
{
   if ( < switch pressed > )
   {
     flagActive = 1;
   }

   if ( flagActive > 0 )
   {
     // .... your program
   }  
}

You could also toggle the flag if you intend to deactivate you program by pressing the button again.

   if ( < switch pressed > )
   {
     flagActive = flagActive * -1;
   }

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