Thursday, 24 September 2015

Creating my Robotic app With App Inventor

To create the app that I made to go with my robot I when to the website of App Inventor Google Created App Inventor, to allow anyone to create basic apps.

In this tutorial I will show you how to create an app which can send a command over Bluetooth, for another device to receive the command. I will be showing how I created my app but you can customise it for your own needs.

When you arrive on the website you need to click on “Start new project”. Then name your project.

Creating  a new Project on App Inventor

 I then created the interface of the app. So I had a canvas, which holds all of the sprites which I would be interacting with. I gave my canvas a background image, and each sprite an image. Make sure that you name each of your sprite for then you know what they do. I named mine according to letter represented on each image. I had made a template on paper so I knew where everything would go roughly.

I then added ListPicker, and a button. The ListPicker was for the connect function and the button for the disconnect function. I also added a horizontal arrangement to make the layout of the components neat. Finally I added a Bluetooth client and a notifier. Don’t forget to rename each component for then you it easier to remember what they each do. I made my disconnect button invisible because I want it to come up only when the Bluetooth is connected.

How the interface of my app looked after i added all the components

I then clicked on “Blocks” and started codding.

Place where you need to click to start codding

I started by doing the function which allows me to connect to the device other Bluetooth. So with the ListPicker, I made it show all of the local Bluetooth networks available. Then the next function checks that the connection was successful. If it was the notifier say’s “connected to Bluetooth” and the connect ListPicker becomes invisible and the disconnect button becomes visible. Else it calls the notifier and say’s “could not connect to Bluetooth”

How my code looked after creating the connect function

I then moved on to the disconnect function. All this does is check that the Bluetooth client is connected and then disconnects it. The notifier then say’s “disconnected form Bluetooth”, and the ListPicker become visible and the disconnect button becomes invisible. Else the notifier say’s “could not disconnect form Bluetooth”

HOw my code looked after creating the disconect function

The next functions send’s the signal to the receiver. In my case an Arduino.
So when the Sprite is pressed down the Bluetooth client send’s the required signal in my case a particular letter. And then I made the picture change for then you could tell that you were properly pressing the right button.

The function next to it is the opposite. So then the sprite is released the Bluetooth client sends another signal and for me that was to say to the Arduino stop. Once again I made the picture change for then I knew I was not pressing it anymore.

I repeated this function for each sprite I had but I changed the value of what is was sending.

Sample of all the main functions

How a button looked after i puched it

How a button looked after a released  it

One if the sprites I had, had to have a different function as I wanted it to keep sending the same signal until I pressed it again.

So I had to create a global variable and set it to false. Then the function had to check and see if the variable was true or false every time I pressed it. If it was false it would send one signal and change the picture and if it was true it would send another signal and change the picture back.

Function of my light switch

The last function I created was to close the app. I wanted to close the app properly every time otherwise sometimes it bug out and still think it was connected to a Bluetooth device when it was not. All this function does is that it check do you want to close the app.

The Exit Function

And that’s how I created my app.

Any question don’t hesitate to contact me

No comments:

Post a Comment