Buttons can be connected to any of the digital pins on your Arduino/Genuino Uno or Mega, labelled 2-13 on the Uno and 2-53 on the Mega. They can also be connected to any of the or any of the analogue pins, labelled A0-A5 on the Uno and A0-A15 on the Mega, as shown in this example:
The 10kΩ resistor (kΩ is pronounced ‘kilo Ohm’) is being used here as a pulldown resistor. Its function is to pull down the input pin to ground (a voltage of 0V) when the button is not being pressed, and to avoid a short-circuit occurring when the button is pressed.
Once your button is connected to your Arduino/Genuino Uno or Mega, use the Connect command to give it a name and tell MECControl which pin it is connected to:
Connect Start Button To Pin A5
In this example, a Button named Start has been connected to the analogue pin labelled A5. You can then refer to the button by name in later commands, as in this example:
Wait For Start Pressed
This Wait command pauses the sequence until the Start button is Pressed. You could just as easily wait until the button is Released:
Wait For Start Released
The commands High and Low or On and Off can be used in place of Pressed and Released if you prefer.
Sometimes it is useful to give the button actions names that mean something in the context of your project.
You can do this by adding named Actions to the end of the Connect command:
Connect EndStop Button To Pin A5 With Actions Hit NotHit
If the button, now named EndStop, is used to detect when a mechanism has hit the end of its travel, this action can be detected using the command:
Wait For EndStop Hit
The Jump command can also be used to jump playback to a labelled line when a button action occurs:
Jump To StopMotor If EndStop Hit
Buttons and switches are treated in similar ways by MECControl, but there is one important difference:
A Button action will be remembered until a Wait or Jump command checks to see if the action is occurring.
A Switch action will be missed if it isn’t happening at the exact moment that a Wait or Jump command checks to see if the action is occurring.