Sunday, April 5, 2015

Ease of App Inventor Coding

Using App Inventor 2 to write apps for a phone is so easy an 11 year old or 13 year old can do it (see video above).   You do not need to install and setup some big development environment.   It is mostly done on a web page.  The steps are:
  1. On your phone or tablet go to Play Store and download "App Inventor 2 Companion".  This app will download and install your app when you point the camera at a 2D bar code later.
  2. On your desktop computer go to   
  3. You first make a user interface by grabbing things like buttons and dropping them on the image of a phone.
  4. Then you click on "blocks" (top right) and you write the code.  For each user interface thing there are things you can get, like if the Button is called "Forward" you can get a "" that will run when the button is clicked.  Then you put whatever code you want in there.   To write your code you drag and drop things that then snap together.    So you click on "control" and drag an "if then else", then click on procedures and get a "Call Forward", etc.   Unlike most computer languages, it really helps prevent you from making lots of kinds of mistakes.  It is really fun to use.
  5. When you want to test the code you click "Build" near the top.  Then run app inventor companion on your phone/tablet and click "scan QR code" and point it at the 2D barcode that will show up on the screen.  It will then download the code and ask if you want to install it, then open it.   It will also be a regular app on your phone that you can run later.

In the image above you can see the block for HornOff.Click which is what is called when you touch the "Horn Off" button in the Manual Mode in our app.  This then calls the function "HornOff" which sends a "q" by bluetooth to the relay controller.  This is the code for turning off the relay that the horn is using.

The Forward code sends "ef" to the relay controller, which turns on the two relays for the two motors.

Above is the code that does the Morse code.  First it divides down the regular clock, only doing something every MorseCodeClockDivider ticks of the regular clock.  Then it reads out from a string if it is supposed to be on or off at this time.  Then it turns the horn or light on or off.

 Above is the code that decides if the boat should turn left, turn right, go forward, or stop.  Do a "right click" and then "view image" to make it a bit larger so you can read everything.  There are 3 main types of boat movement this has to handle.
  1. GoTo - where the boat is trying to get to some GPS coordinate. 
  2. ParkBoat - where the boat wants to stay near some GPS coordinate
  3. AimBoat - where the boat is trying to point at some location (for horn or light to reach someone)
This is the most complicated part of the code and it did require some walking around with the phone to test and debug before it all worked right.

I think that if one person on your project has computer programming experience then using App Inventor will be fine for everyone.   It was my 2 older boys first experience programming computers and I think it is a great way to start.   If you use our code you will be able to do all kinds of things without changing any code.  We will document our "Robot command language" in a future post.

Early on any of our computers were fine for App Inventor.   As our code got larger it got slower to move around the screen on our older computers.  Eventually it got too painful on most of our computers.   Now we only work on our main app using our fastest computer.  This is the lowest end Dell gaming computer (Alienware) as of January 2015.  On this computer editing is still very fast.  This computer also has a 32 inch screen, which really helps for this graphical programming method.   These huge screens are down to like $150.  They are so nice I think all computers should have them.

No comments:

Post a Comment