Tecnologia do Blogger.
RSS

[androidbrasil-dev] Send Two Data To Android (Amarino)

Hey guys...

I make an app that receives data from a potentiometer (arduino).

This app is ok, but I have to sendo data from two  potentiometers and I'm in trobles with it....

This my sketch and my app... anyone can help me ?

AMARINO SKETCH
=============================================================
#include <MeetAndroid.h>

MeetAndroid meetAndroid;
int sensorValue = A0;
int sensorValue1 = A1;

void setup() {
  Serial.begin(9600);
}

void loop() {
  meetAndroid.receive();
  delay(1000);
  meetAndroid.send(analogRead(sensorValue));
 delay(1000);
}

=============================================================
ANDROID CLASS
=============================================================

package sp.teste.br.testepotenciometro;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
import at.abraxas.amarino.Amarino;
import at.abraxas.amarino.AmarinoIntent;

public class MainActivity extends Activity implements {

    public static final String DEVICE_ADDRESS = "30:14:10:29:09:30";
    private TextView tvSensor, tvSensor1;
    private ArduinoReceiver arduinoReceiver = new ArduinoReceiver();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        tvSensor = (TextView) findViewById(R.id.tvSensor);
        tvSensor1 = (TextView) findViewById(R.id.tvSensor1);
    }

    @Override
    protected void onStart() {
        super.onStart();
        Amarino.connect(this, DEVICE_ADDRESS);
        // Faz com que o Android receba dados do arduino (ACTION_RECEIVED) e repassa para um broadcast receiver (arduinoReceiver)
        // registerReceiver:
        // arduinoReceiver = BroadCastReceiver
        // IntentFilter = instancia um novo filtro de intent com os dados recebidos do arduino
        registerReceiver(arduinoReceiver, new IntentFilter(AmarinoIntent.ACTION_RECEIVED));
    }

    @Override
    protected void onStop() {
        super.onStop();
        Amarino.disconnect(this, DEVICE_ADDRESS);
        unregisterReceiver(arduinoReceiver);
    }


    public class ArduinoReceiver extends BroadcastReceiver {
        // Método acionado ao receber dados
        //  registerReceiver(arduinoReceiver, new IntentFilter(AmarinoIntent.ACTION_RECEIVED));
        // context = arduinoReceiver e intent = AmarinoIntent
        @Override
        public void onReceive(Context context, Intent intent) {
            String data = null;

            final String address = intent.getStringExtra(AmarinoIntent.EXTRA_DEVICE_ADDRESS);

            final int dataType = intent.getIntExtra(AmarinoIntent.EXTRA_DATA_TYPE, -1);

            if (dataType == AmarinoIntent.STRING_EXTRA) {
                data = intent.getStringExtra(AmarinoIntent.EXTRA_DATA);

                if (data != null) {
                    try {
                        tvSensor.setText(data);
                    } catch (NumberFormatException e) {
                        Toast.makeText(getBaseContext(), e.getMessage().toString(), Toast.LENGTH_LONG).show();
                    }
                }
            }
        }
    }
}


Thanks...

--
You received this message because you are subscribed to the Google Groups "Android Brasil - Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to androidbrasil-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

  • Digg
  • Del.icio.us
  • StumbleUpon
  • Reddit
  • RSS

0 comentários:

Postar um comentário