Controlling the Fantastic Robot with AppInventor

Controlling the Fantastic Robot with AppInventor

per Citilab Edutec

Boards
Plaques:

Citilab ED1

Component/s
Components:

Cap

Controlling the Robot with App Inventor

App Inventor

  • App Inventor is a block-based visual programming environment for creating applications for Android and iOS devices. It was initially developed by Google Labs in 2008, and is currently maintained by MIT (Massachusetts Institute of Technology).

Kids programming in App Inventor

  • Allows you to create applications in an easier way and in less time than with other more complex environments.

  • Apps can be tested in real-time before being compiled and installed on the device.

  • It has many tutorials to learn independently in addition to a very large community that shares its projects.

App Inventor Tutorials

Getting started with App Inventor

  • Go to App Inventor website.

  • Click on the button that says Create Apps!.

  • Click on "Continue Without An Account", or enter your Google account credentials if you have them.

  • Click on Continue in the welcome window that appears below.

App Inventor Welcome Screen

Create a new project

  • Optional: Change the language by clicking on English (above and on the right) and select your preferred language.

  • Create a new project by clicking Projects→Create a new project menu option.

Create New Project

  • Name it (for example RobotED1) and click the OK button.

Name the Project

Synchronize with the AI Companion

  • The MIT AI2 Companion is a mobile application that acts as a real-time testing tool for applications created with MIT App Inventor.

  • Download the MIT AI2 Companion to your Android or iPhone mobile or tablet and open it.

Download Companion

  • Click on Connect→AI Companion menu option.

Connect the Companion

  • Scan the QR code with the Scan QR Code option or write the code directly.

Scan QR Code

  • NOTE: The computer and device must be on the same network.

Adding buttons

  • We will start by adding buttons to be able to send commands to the robot. To add one, drag the Button element from the Palette to the Viewer.

Add button

  • Then we can change the names of these buttons by selecting them and clicking the Rename button (putting ButtonForward for example).

Rename Button

  • We can also change the text it shows by going to the Properties section and modifying the Text property, introducing a new one (putting Forward for example)

New name

Challenge 1: Add 3 more buttons and change their name and display text.

Challenge

Solution to challenge 1

Solution challenge 1

Organize the buttons

  • By default App Inventor places the screen components one under the other. To organize the components we need the elements found in the Layout category.

  • If we want to place the buttons in a distributed manner on the screen, we can use combinations of the VerticalArrangement and Horizontal Arrangement or the Table Arrangement.

Table Arrangement

Challenge 2: Place the buttons like those on a remote control.

Challenge

Solution to challenge 2

Button arrangement

Change button size

  • When we add a visual component to our application they have the Height and Width properties set as Automatic. This means that their content is adjusted, as in the case of text of the buttons.

  • If we want to make the buttons have regular dimensions (square shape) we can assign a specific value of pixels in both properties, for example 100.

Change button size

Detect pressed button

  • To start programming the application, go to the Blocks section, next to Designer.

Section Blocks

  • Once inside, to detect when we press a button, select it in the Blocks section and take the when ButtonForward.Click block.

when Button click

Note: App Inventor block images can also be dragged into the App Inventor block editor to retrieve code.

Send Web requests

  • In order to send web requests we need the Web component in the Connectivity category.

Web Component

  • To make a web request we go to the Designer and add the set Web1.Url to block to specify the address and the call Web1.Get block to execute the request.

Web URL Block

Block Web get

  • To put the address we must use the " " block available in the Built-in→Text category.

URL text block

Challenge 3: Make each button execute the corresponding web request when pressed.

Challenge

Solution to challenge 3

Solution challenge 3 Solution challenge 3 Solution challenge 3 Solution challenge 3

CC-BY-SA

© per Citilab Edutec 2019-2022.
Aquesta obra té una llicència CC-BY-SA 4.0.