Need help to configure Me4Button in mBlock


#1

Hello. Could somebody give me guidance how to use Me4 button to driving dc motor ? I have Orion board and I need to use one button to increase speed of the motor and second one to reduce speed ? I want to to use two button to control left and right motion and two others to control speed. How to configure it in mBlock ? I would be grateful for short instruction, the best way will be screen shot from mBlock . Thanks


#2

I don’t have an Orion board robot built (yet), but I suspect it would be something like the program below:

You’d need to configure the port that the MeButton is connected to (the example shows Port6). I chose an increment of 25 but you can adjust that to your needs. I am arbitrarily assuming that the left motor is M1 and the right motor is M2 in this example.

Walkthrough:

  1. Initialize the LeftMotorSpeed / RightMotorSpeed variables to zero.
  2. Begin the forever loop
  3. If button 1 is pressed, increase the value of the LeftMotorSpeed and RightMotorSpeed variables by 25.
  4. If button 2 is pressed, decrease the value of the LeftMotorSpeed and RightMotorSpeed variables by 25.
  5. If button 3 is pressed, decrease the value of the RightMotorSpeed variables by 25.
  6. If button 4 is pressed, decrease the value of the LeftMotorSpeed variables by 25.
  7. Set the speed for each motor.

This is not a complete program and you’d to fiddle around with it to make sure it works the way you want, but I think it is a reasonable example of using the MeButton to control the motors. I should mention that this will provide a steering (think automobile) turn, not an in-place tank-like turn.

Hope this helps.


#3

Thank you so much it works !!!. Only problem I need to solve is how to upload it to arduino because I still getting error " Could not create sketch. " Any idea ?


#4

Make sure that your sketchbook folder has write permissions. The only reason I can think of for that type of error. :slight_smile:


#5

Great. Thanks? It is for camera slider. I wonder if you know also how to add MePotentiometer module for this application to set up period of time for break in motion (you know like for timelapse -Motor stops for 10 second than moves, stops and again moves. )Using Me potentiometer I would be able to choose how many second I need for break motion option. Any idea ? It would be awsome if you know that. :wink:


#6

Hi. Could you please take a look at my project ? Everything works fine ( from mBlock ) until I upload it to Arduino, than only two button works and only one speed. Something is missing ?


#7

Not sure what to tell you, it looks correct.

@tec_support, can you provide any insight?


#8

There needs to be a “wait for button to be released” command in each “if” block to stop the code looping multiple times when a button is pressed.


#9

Good catch!


#10

The only two things I can think of are the permissions on the folder (which I’ve already mentioned) or if the folder doesn’t exist (check the Preferences->Sketchbook location and make sure that exact path exists).


#11

what is the code/command to check Me 4-Button “release” event. I only see command for Me 4-Button “pressed” event.


#12

Try using a Not block around the button pressed block, i.e.,

if ( (Not < (button (Port 3) (Key 1) pressed) )