Start/Stop Program Using Button


#1

Can someone help me, please? How do I add a piece to my program that will allow me to start or stop running the program by pressing the green button on the mBot? Thanks in advance!

Also, if anyone has any really good tutorials they’d recommend, I would love to find them. I am looking at this for elementary and middle school kids, but I am not a coder, and the company’s instructional materials are unadulterated crap.


Getting started
#2

if I were to use the onboard button to toggle a program I would do it in a way that there was a positive feedback that the button event had occurred and which state (on or off) it was in.
For the mBot a high beep or onboard led would work great to say “I am on” and a low beep or led off would be of the off state.
Since the button is a momentary contact type of button you have to put in code that “de-bounces” the button. Basically it is looking for a change in state (pressed) and has to stop looking till the state returns (released).
here is a sample bit of scratch code
You can download the scratch source here: mbot_button_toggle.sb2 (73.7 KB)


#3

Dan do we have to keep everything for that to work? I am messing around and found out if I move something then it disappears and does not work anymore.


#4

Can you clarify? I’m not sure what you mean by “moving something”.


#5

Turn robot on. Then it starts the program when I hit the button.


#6

This was helpful. Thank you. I’ve simplified it a lot to use with my 6th grade class. This is the code I’m giving them to get them going based on what I learned from your code:

Once they understand why this works, they can use it to create a pattern of movement for their robot that they can start by pushing the button.


#7

Hi,
could you tell me where the ‘button pressed’ block is.
Thanks
Joe


#8

Hi Joe,

Please see picture below:


#9

Thanks for the reply,
I’m still getting confused between the mbot and the meOrion. I cannot see this block when I select meOrion in the boards menu. Could you tell me why the same blocks are not available for both boards. On my meOrion I have a button but no block for it.
Joe


#10

Hi Joe,

On the Orion board, there is only a reset button. On mCore, there is an on board button besides the reset button.


#11