MagicCode Lesson 1
What is MagicCode?
Introduction to magiccode
MagicCode is a Scratch 3.0 based graphical programming software that makes you learn to code superfast. If you are new to the world of programming, MagicCode is one of the best companions that makes coding fun and easy. The user-friendly interface and drag and drop functionality make coding more interesting because of no need to worry about traditional programming rules. You can create your interactive games, animations, or program robots and projects with MagicCode. You can directly connect your Magicbit, Arduino, or Microbit boards with MagicCode and control generic sensors and actuators, or It also has an upload mode where you can upload your code inside boards.
MagicCode interface and tools
A block is like a jigsaw puzzle piece that is used to write programs by simply dragging and dropping them below one another in the scripting area. Blocks are often easier to work with than text-based programming, as one has to memorize the commands typed and syntax errors may occur. There are ten categories of blocks: Motion, Looks, Sound, Event, Control, Sensing, Operators, Variables, List, and My Blocks. The list blocks are shown under the Variables Blocks.
- Block palette
The block palette is under the Code tab. It consists of different palettes such as Motion, Sound, and Control. Each palette has different blocks that perform functions specified by the palette name. There are other varieties of block palettes that can be loaded from the Add Extension button located at the left bottom.
A script is a program or code in MagicCode which is a collection or stack of blocks that all interlock with one another. The blocks and their order are very important, as they determine how sprites interact with each other and the backdrop. Sometimes, comments are attached to scripts to explain what certain blocks do and what the script’s purpose is. You can write multiple scripts, all of which can then run simultaneously.
- Connect Devices
Connect Devices is used to connect devices (Magicbit, Arduino, or Microbit) with MagicCode.
- Add Extensions
Add Extensions are used to add new palettes to the block palette.
Sprites, either user-created, uploaded, or found in the MagicCode Sprites library, are the objects that perform actions in a project. Most projects have at least one sprite as well because only sprites can move.
Users can give instructions to a sprite (such as telling the sprite to move) by snapping blocks together in the script area. Clicking on the block(s) in the script area will cause the sprite to react based on the function of the block(s) clicked. Clicking on a sprite’s thumbnail in the sprite pane will bring up the script area of that sprite.
The look of a sprite can also be changed by using costumes. The current costume of a sprite can be changed by clicking on the “costumes” tab and clicking on the desired costume of choice, or by using look blocks to select the sprite’s costume. New costumes for the sprite can be imported, created, and edited in the MagicCode Paint Editor.
Some sprites additionally have at least one sound. Unlike costumes, sounds are an optional field, so you can have a sprite with no sounds. The sounds tab allows you to add, delete, and edit sounds. Sounds can be played in the sound editor or with blocks that play a specific sound. Sprites (with all of their scripts, costumes, and sounds) can be exported, and then imported into another project if desired. This is achieved by right-clicking on a sprite’s thumbnail in the sprite pane and then selecting “save to local file” in the pop-up menu. A sprite can also be dragged into the backpack and dragged out into another project for transporting. However, this will not save the sprite to one’s computer.
The stage is the background of the project where your sprites perform their actions, but it can have scripts, backdrops (costumes), and sounds, similar to a sprite, and it has its own scripts and sounds. But the stage has some restrictions on sprite functions, such as motion and size blocks.
The stage is 480 pixels wide and 360 pixels tall. All sprites have a particular position on the stage. However, no sprites can move behind the stage, and it is always at the back layer.
The Device tab is the place where you can connect your boards with MagicCode. MagicCode provides facilities to connect five boards. You can connect your Magicbit, Arduino UNO, Arduino Mega, Arduino Nano, or Microbit Boards with MagicCode. You can program your board either in live mode or Upload mode.
In the Live mode, you can view the program execution effect in real-time, which facilitates the commissioning of the program.
In this mode, you must keep the board connected to MagicCode. If it is disconnected, then the program cannot be executed.
In the Upload mode, you need to upload the compiled program to the device. After being successfully uploaded, the program can still run properly on the device when the device is disconnected from MagicCode.
Connecting Magicbit with Computer
There are two ways to connect a MagicBit to the computer.
- Wirelessly through WiFi (Useful when using magiccode for robotics and sensing applications).
- Through a USB cable from a serial connection.
If you have MagicbitOS installed in your magicbit, you can select magiccode-WiFi option to program magicbit board with magiccode. Continue from step 3 if you have magicbitOS.
1. Connect your device to the pc with a USB Connector. Alternatively, you could connect your magicbit to a 5V phone charger or a 3.7V battery too.
2. Upload magicbitOS firmware using magicbit uploader.
Select the correct serial port and click on magicbitOS button.
Now you can connect the board to a battery, a powerbank, or a phone charger brick. and wirelessly program the magicbit.
3. Boot from magiccode.
On the boot menu, using left key, select magiccode and press left key to load it.
4. Connect to magiccode
Then a SSID and a password will appear on the screen.
Go to wifi settings in the computer and select the wifi SSID name displayed on the Magicbit screen with the password. This will connect the board with the computer via wifi to communicate wirelessly.
5. Start building with magiccode
Open MagicCode software and select the devices tab.
Choose the Wi-Fi option and click on connect. This will connect the software to the board.
If everything works properly disconnect button will appear.
Now you can execute magiccode comands as usual.
Using USB mode.
1. Connect your device to the pc with a USB Connector.
2. Upload magicCode firmware using Magicbit Uploader
Select the correct serial port and click on magiccode icon.
Select USB option. Then magiccode firmware will be loaded on to the magicbit.
3. Go to the Device tab at the down right corner of the MagicCode interface.
3. Select Live Mode.
4. Select your Device by clicking the Select button.
The above Devices’ library is displayed after clicking the select button and select your devices from the library.
5. Select the Serial port where the device is connected.
Click on the USB mode button. Then serial port selection menu will appear.
If you don’t see any port in the select port menu, then click the refresh button. The following figure, displays the select port menu.
6. Click the connect button and connect your device to MagicCode.
After the device has connected, the “Connect” button changes to the “Disconnect” button and the icon changes.
Now you can create and execute your program with your board.