Once you have imported the MekaMon Playground and connected your robot, you're ready to start testing your MekaMon! Coding your robot is easy, even if you haven't programmed before or used Swift. Nevertheless, getting your head around the process may be daunting, so we've put together a walkthrough guide for the first challenge to get you up and running. Consult our Glossary for any bolded terms you don't recognise, or simply to gain more understanding of the processes you are employing in your program!
This is the first screen you will face once you've passed the introduction. Along the top you can see which stage of the testing process you are on, and view (or skip to) different chapters within the playground using the bullet point icon on the left.
Along the bottom of the image, you will find the option to Run My Code. Once you have finished inputting your program this button will allow you to see it in action. The timer icon to the left of it allows you to Step Through My Code which will highlight each stage of your program as your MekaMon performs it for precise adjustments! Step Slowly also achieves this, but at a slower pace.
Below the image you will find your current Goal as well as step by step instructions on how to achieve this goal using Swift programming language.
Finally, you have your coding space. This is where you will input your code according to the instructions above!
Programming The Walking Diagnostic
1. Our first instruction is to put MekaMon into movement mode by using the setMode function. Heading down to our coding space then, we can tap to start programming and select SetMode (mode:Mode) from the suggested inputs along the bottom of the screen. Continue tapping through the suggested inputs until you have a full function and argument reading setMode (mode: Mode.walking). (Mode: Mode.X) tells your robot that you are about to give it an instruction, and then providing that instruction with Mode.walking.
2. Tap the return button to move onto the next line and we can use the setSpeed function in the same way, this time inputting a number to set the walking speed of the robot. Once we set the speed we have successfully told our robot that we will be issuing a command to walk and that it should walk at a certain speed.
3. Select the option Walk from the input suggestions below. The function to walk can be customised with an argument to set the direction your robot will walk in. This is controlled by angles. Set the angle as 90 to walk to the right, 180 to walk backwards, 270 to walk left, and 360 to walk forwards. In this case, we need to start by walking forwards so set the angle as 90 in your argument.
4. On a new line, select Wait from the input menu below and you will be asked to input another number. This will dictate how long the MekaMon will move before it comes to a stop, measured in seconds. As per the instructions, set this time to 2.
5. In order to have our robot move forward, backward, left, and right, repeat steps 3 and 4 using different walking angles each time to set different directions until you have walked your MekaMon in all directions.
6. Remember to call the Stop function at the end to finish your program.
Testing Your Program
Once you've finished entering your code, you can run it to check it works. Simply tap the option to Run My Code and watch your MekaMon moving according to your instructions. If there is anything wrong with your code, a message will display what you need to fix in order to run the program effectively. You can always also tap the Hint button to display any issues in your code before you test it.
Your completed Walking Diagnostic code should look something like this: