|   FORUM      |     Tutoriales    |     KIO4 |      
   Start B4A (Basic4Android) App inventor 2 Arduino
   Elastix - VoIP Things of Windows Interesting Webs  Telecomunications

 


Nuevo concurso para España, Argentina, Brasil, Chile, Colombia, Ecuador, México, Perú y Portugal.

App Inventor 2
Programming mobile phones with Android 
by App Inventor 2 - Juan Antonio Villalpando

- Initiation Tutorial App Inventor 2 -

Return to tutorial index

____________________________

Sensors

17.- Accelerometer Sensor.

ip17_accelerometer

- Moving the mobile shows the change acceleration: x, y, z.

- In this example, when you move the screen changes its background color.
- The background color you get by mixing three RGB colors, each of which has 255 tones. Each of these tones are randomly obtained.

_________________
Design

_________________
Blocks

- Additive color mixing. By adding Red, Green and Blue, obtain any other color
- Each color RVA, has 255 different shades, from 1 to 255. (this example 1-255)

- In total you can get 255 x 255 x 255 = 16,581,375 colors


_____________________________________________

- Proposal 1: (easy)

- Get the total acceleration vector

t = sqrt (x2 + y2 + z2)

- Proposal 2:

Account leaps. (It is difficult)

- Make a program where the user paste hops, each hop will one in a counter that is displayed.

- Here's an example of hopping account: pedom_ewen.aia the forum.

_______________________________
17B.- Accelerometer. Shake.

ip17B_shake

- When we shake the mobile / tablet, the Background Screen gets a random color (RGB).
- Also is written on a Label number random from 1 to 6.

_________________
Design

_________________
Blocks

_______________________________

18.- BarcodeScanner and WebView.

p18_codigo_de_barra

- By BarcodeScanner we can scan a QR code, we get the text of QR decoded.

- In this case I also used a WebView, is at the controls of the User Interface.

- Press the Button, scan QR code, after a few seconds get your text and website.

- For examples let's Google, wrote QR and click on Images. Obtain many QR to consult.

_________________
Design

_________________
Blocks


_______________________________

19.- Create a QR. BarcodeScanner and ActivityStarter.

ip19_create_qr

- Through the website http://qrcode.kaywa.com/ we can send a text and returns us QR.

- To do this we need to communicate with your web, we continue this process.

- It situate one ActivityStarter, is in Connectivity.

- In its Property Action, we wrote this: android.intent.action.VIEW

_________________
Design




The ActivityStarter is Connectivity

_________________
Blocks

- In ActivityStarter1.DataUri:

http://qrcode.kaywa.com/img.php?s=20&d=

The 20 indicates the size of the QR, you can put another number.

To make it work, we write something in the TextBox1 and press the Button. The program will communicate via the Internet with that page and text TextBox1.Text and displayed on the screen corresponding to that text QR.
_____________________
Proposal.

With the code we just saw with the web of qrcode.kayawa, performs a program where you write a text, pressing a button that text QR code is created.

We scan the QR code that we have obtained and we write the message, pronounce and translate into Spanish.

_______________________________

20.- LocationSensor.

ip20_location_sensor

- Obtain geographical coordinates by GPS. We can also get the address of that place.

- DistanceInterval, we can put one meter and when we move the location that distance is obtained.
- TimerInterval, 1,000 milliseconds coordinate a query is made.

- We can write a location and we get coordinates, for example we write Grazalema and give us the coordinates of that location.

_________________
Design

_________________
Blocks

_______________________________

20B.- LocationSensor. GPS and Google map.

ip20B_GPS_map_Google

- We press one Button1 and get in the TextBox1 and TextBox2 the latitude and longitude of our position. In addition, a map of Google address these coordinates is created and through a WebView see a Google map with the location.

- Write latitude and longitude coordinates in the TextBox. Press Button2 and displayed in the WebViewer the map of Google for that position.

- At TextBox we will mark the Property NumberOnly and delete the text hint.
_________________
Design

_________________
Blocks

- Note that I have set intermediate variables as latitudz and longitudz , as latitude and longitude are variables that only act on the Block LocationSensor1.

- In Button2:

https://www.google.es/maps/@

m/data=!3m1!1e3

_______________________________

21.- OrientationSensor.

ip21_orientation_sensor

By moving the mobile, the orientation of it is displayed.

  • Roll: 0º when the device is level, increasing to 90º as the device is tilted up onto its left side, and decreasing to -90º when the device is tilted up onto its right side.
  • Pitch: 0º when the device is level, increasing to 90º as the device is tilted so its top is pointing down, then decreasing to 0º as it gets turned over. Similarly, as the device is tilted so its bottom points down, pitch decreases to -90º, then increases to 0º as it gets turned all the way over.
  • Azimuth: 0º when the top of the device is pointing north, 90º when it is pointing east, 180º when it is pointing south, 270º when it is pointing west, etc.
  • Angle: indicates the angle at which the device is tilted. That is, if you put a ball on the screen at what angle it would move.
  • Magnitude: A number between 0 and 1 when the device is tilted. It indicates the force with which a ball would move on the screen.

In this example, Roll, Pitch and Azimuth are obtained in two different ways.

_________________
Design

_________________
Blocks

_______________________________

22.- OrientationSensor. Canvas. ImageSprite. Compass.

ip22_compass

- Canvas is an area where you can draw, move cartoon-sprites, ball,...
- ImageSprote is a drawing that can be moved around the canvas.

- We put a Canvas.
- Within the Canvas a ImageSprite.
- We upload this image arrow: (flecha2.gif)
- In the ImageSprite establish the Property Photo with flecha2.gif


- We place an OrientationSensor.


flecha2.gif

_________________
Design

_________________
Blocks

When you change the orientation of the mobile, the top (Heading) of ImageSprite is drawn on the angle azimuth.
In this way the top of the ImageSprite always marks the North. That is, it acts as a compass.

You can also put a picture of a compass. Brujula.gif

_______________________________

23.- ProximitySensor.

p23_sensor_de_proximidad

 

It is a sensor located on the top of the moving ahead.

In the figure on the right it is indicated the place where you can find this sensor.

This sensor delivers two values: 0.0 and 1.0 .

(In other models of mobile delivery: 3 and 100)

When no object in front of this sensor delivers the value 1.0
when there is any object within 3 cm (approx.) Of this sensor delivers the value 0.0

There are some phones that the sensor delivers the distance between the object and the sensor.

One use of this sensor could be that when we have the phone away from our ears sounds a loud sound and when it is approached automatically lower the volume of sound.

 

         

_________________
Design

_________________
Blocks

Proposal:

- Create an application so that when you press a button starts ringing a song and when you approach the phone to ear automatically lower the volume of the song.

_______________________________

23B.- NFC. Near Field Communication.

Communication electromagnetic field nearby. It is used to pass information from one phone to another by electromagnetic field.
The phones with NFC have a coil acting as an antenna transmitting / receiving. They can send information to another mobile near emitting an electromagnetic signal, such as radio broadcasts at a frequency of about 13.56 MHz.
The mobile emitter and receiver must be very close.

__________________________________

 

- My e-mail:
juana1991@yahoo.com
- Who I am. - Cookies. Texts and images propierty autor:
© Juan A. Villalpando
Not copy texts neither images.
We use our own cookies and third-party cookies on our websites to maintain the session and your preferences, customize your user experience and obtain website use statistics.
Si continúa navegando consideramos que acepta su uso. OK    Más información