使用HC-06蓝牙模块从Android向Arduino发送数据

使用HC-06蓝牙模块从Android向Arduino发送数据,android,bluetooth,arduino,Android,Bluetooth,Arduino,我已经创建了一个Android应用程序,使用蓝牙与我的Arduino通信。但当我从Android设备向Arduino发送数据时,Arduino对我发送的数据没有响应。我能够从我的Android设备连接到我的Arduino。所以这不是问题所在 这是我的Android完整脚本 package nl.handoko.LumaMini; import java.io.IOException; import java.io.OutputStream; import java.util.UUID; im

我已经创建了一个Android应用程序,使用蓝牙与我的Arduino通信。但当我从Android设备向Arduino发送数据时,Arduino对我发送的数据没有响应。我能够从我的Android设备连接到我的Arduino。所以这不是问题所在

这是我的Android完整脚本

package nl.handoko.LumaMini;

import java.io.IOException;
import java.io.OutputStream;
import java.util.UUID;

import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothSocket;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity {
    private static final String TAG = "LumaMini";
      private static final int REQUEST_ENABLE_BT = 1;
      private BluetoothAdapter btAdapter = null;
      private BluetoothSocket btSocket = null;
      private OutputStream outStream = null;

      Button fourty, thirty, twenty, twelve, automatic, manual;
      TextView message;

      // Well known SPP UUID
      private static final UUID MY_UUID =
          UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"); 

      // Server's MAC address
      private static String address = "98:D3:31:30:09:43";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.d(TAG, "In onCreate()");
        setContentView(R.layout.activity_mainnn);

        fourty = (Button) findViewById(R.id.button1);
        thirty = (Button) findViewById(R.id.button4);
        twenty = (Button) findViewById(R.id.button2);
        twelve = (Button) findViewById(R.id.button5);
        automatic = (Button) findViewById(R.id.button3);
        manual = (Button) findViewById(R.id.button6);

        message = (TextView) findViewById(R.id.textView1);

        fourty.setText("40 Leds");
        thirty.setText("30 Leds");
        twenty.setText("20 Leds");
        twelve.setText("12 Leds");
        automatic.setText("Automatic");
        manual.setText("Manual");
        message.setText("Using this app you can take full control of the Luma Mini!" +
                "When it's running on automatic please switch back to manual first before switching to other versions.");

        btAdapter = BluetoothAdapter.getDefaultAdapter();
        checkBTState();

        fourty.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
              sendData("a");
              Toast msg = Toast.makeText(getBaseContext(),
                  "40 Leds version", Toast.LENGTH_SHORT);
              msg.show();
            }
          });
        thirty.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
              sendData("b");
              Toast msg = Toast.makeText(getBaseContext(),
                  "30 Leds version", Toast.LENGTH_SHORT);
              msg.show();
            }
          });
        twenty.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
              sendData("c");
              Toast msg = Toast.makeText(getBaseContext(),
                  "20 Leds version", Toast.LENGTH_SHORT);
              msg.show();
            }
          });
        twelve.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
              sendData("d");
              Toast msg = Toast.makeText(getBaseContext(),
                  "12 Leds version", Toast.LENGTH_SHORT);
              msg.show();
            }
          });
        automatic.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
              sendData("e");
              Toast msg = Toast.makeText(getBaseContext(),
                  "Run automatically", Toast.LENGTH_SHORT);
              msg.show();
            }
          });
        manual.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
              sendData("f");
              Toast msg = Toast.makeText(getBaseContext(),
                  "Manually switch Leds", Toast.LENGTH_SHORT);
              msg.show();
            }
          });
        }
    @Override
    public void onResume() {
      super.onResume();

      Log.d(TAG, "...In onResume - Attempting client connect...");

      // Set up a pointer to the remote node using it's address.
      BluetoothDevice device = btAdapter.getRemoteDevice(address);

      // Two things are needed to make a connection:
      //   A MAC address, which we got above.
      //   A Service ID or UUID.  In this case we are using the
      //     UUID for SPP.
      try {
        btSocket = device.createRfcommSocketToServiceRecord(MY_UUID);
      } catch (IOException e) {
        errorExit("Fatal Error", "In onResume() and socket create failed: " + e.getMessage() + ".");
      }

      // Discovery is resource intensive.  Make sure it isn't going on
      // when you attempt to connect and pass your message.
      btAdapter.cancelDiscovery();

      // Establish the connection.  This will block until it connects.
      Log.d(TAG, "...Connecting to Remote...");
      try {
        btSocket.connect();
        Log.d(TAG, "...Connection established and data link opened...");
      } catch (IOException e) {
        try {
          btSocket.close();
        } catch (IOException e2) {
          errorExit("Fatal Error", "In onResume() and unable to close socket during connection failure" + e2.getMessage() + ".");
        }
      }

      // Create a data stream so we can talk to server.
      Log.d(TAG, "...Creating Socket...");

      try {
        outStream = btSocket.getOutputStream();
      } catch (IOException e) {
        errorExit("Fatal Error", "In onResume() and output stream creation failed:" + e.getMessage() + ".");
      }
    }

    @Override
    public void onPause() {
      super.onPause();

      Log.d(TAG, "...In onPause()...");

      if (outStream != null) {
        try {
          outStream.flush();
        } catch (IOException e) {
          errorExit("Fatal Error", "In onPause() and failed to flush output stream: " + e.getMessage() + ".");
        }
      }

      try     {
        btSocket.close();
      } catch (IOException e2) {
        errorExit("Fatal Error", "In onPause() and failed to close socket." + e2.getMessage() + ".");
      }
    }

    private void checkBTState() {
      // Check for Bluetooth support and then check to make sure it is turned on

      // Emulator doesn't support Bluetooth and will return null
      if(btAdapter==null) { 
        errorExit("Fatal Error", "Bluetooth Not supported. Aborting.");
      } else {
        if (btAdapter.isEnabled()) {
          Log.d(TAG, "...Bluetooth is enabled...");
        } else {
          //Prompt user to turn on Bluetooth
          Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
          startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
        }
      }
    }

    private void errorExit(String title, String message){
      Toast msg = Toast.makeText(getBaseContext(),
          title + " - " + message, Toast.LENGTH_SHORT);
      msg.show();
      finish();
    }

    private void sendData(String message) {
      byte[] msgBuffer = message.getBytes();

      Log.d(TAG, "...Sending data: " + message + "...");

      try {
        outStream.write(msgBuffer);
      } catch (IOException e) {
        String msg = "In onResume() and an exception occurred during write: " + e.getMessage();
        msg = msg +  ".\n\nCheck that the SPP UUID: " + MY_UUID.toString() + " exists on server.\n\n";

        errorExit("Fatal Error", msg);       
      }
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {

        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

}
这是我的Arduino脚本:

#include <SoftwareSerial.h>
#include <TimerOne.h>

#define Rx 2
#define Tx 3
#define seconds 4

char serialData;                                                          // Serial data memory
int counter1;                                                             // Overflow memory
int action;                                                               // Action trigger
int once = 0;                                                             // Run only once

SoftwareSerial Bluetooth(Rx, Tx);

void setup(){
pinMode(Tx, OUTPUT);                                                    // Configure Tx as OUTPUT (Transmitter)
  pinMode(Rx, INPUT);
  delay(1000);
  Bluetooth.begin(9600);
  Serial.begin(1200);
  delay(1000);
  Serial.print("Bluetooth ready");
  Bluetooth.flush();
  TimerOneSetup();                                                        // Run the setup for Timer One
  for(int i = 5; i <= 8; i++){                                            // Make pins 5, 6, 7 and 8 OUTPUT
    pinMode(i, OUTPUT);
  }
}

void interrupt1(){                                                        // Timer One loop
  counter1++;                                                             // Count the amount of seconds has passed
  if (counter1 == seconds){                                               // Trigger the next action after a several amount of seconds (Default: 4 seconds)
    action++;
    counter1 = 0;
  }
  if (action > 3){                                                        // Reset action trigger when after all actions were runned
    action = 0;
  }
}

void loop(){                                                              // Endless loop
  if (Serial.available()){                                                // Wait for data recieved from Local device
    serialData = Serial.read();                                           // Put recieved data in memory
    Serial.print("Data recieved from Local device: ");
    Serial.println(serialData);
  }
  if (Bluetooth.available()){                                             // Wait for data recieved from Bluetooth device
    serialData = Bluetooth.read();                                        // Put recieved data in memory
    Serial.print("Data recieved from Bluetooth device: ");
    Serial.print(serialData);
  }
  if (once == 0){                                                         // This script will be run only once
    serialData = 'e';                                                     // Put switch on automatic on startup
    once++;                                                               // Get into the next stage which may be run only once
  }
  switch(serialData){                                                     // Perform action on state of the switch
    case 'a':
      fourtyLeds();                                                       // Show the 40 Leds version of the Luma Mini
      break;
    case 'b':
      thirtyLeds();                                                       // Show the 30 Leds version of the Luma Mini
      break;
    case 'c':
      twentyLeds();                                                       // Show the 20 Leds version of the Luma Mini
      break;
    case 'd':
      twelveLeds();                                                       // Show the 12 Leds version of the Luma Mini
      break;
    case 'e':
      while(serialData == 'e'){                                           // Keep changing different Led versions of the Luma Mini automatically
      switch(action){
        case 0:                                                           // Wait for the action trigger to hit the first action
          fourtyLeds();                                                   // Show the 40 Leds version of the Luma Mini
        break;
        case 1:                                                           // Wait for the action trigger to hit the second action
          twelveLeds();                                                   // Show the 12 Leds version of the Luma Mini
        break;
        case 2:                                                           // Wait for the action trigger to hit the third action
          twentyLeds();                                                   // Show the 20 Leds version of the Luma Mini
        break;
        case 4:                                                           // Wait for the action trigger to hit the fourth action
          thirtyLeds();                                                   // Show the 30 Leds version of the Luma Mini
        break;}
        if (Serial.read() == 'f'){                                        // Wait for data recieved from Local device
          serialData = Serial.read();                                     // Put recieved data in memory
          Serial.print("Data recieved from Local device: ");
          Serial.println(serialData);
        }
        if (Bluetooth.read() == 'f'){                                     // Wait for data recieved from Bluetooth device
          serialData = Bluetooth.read();                                  // Put recieved data in memory
          Serial.print("Data recieved from Bluetooth device: ");
          Serial.println(serialData);
        }
        break;
      }
  }
}

void BluetoothSetup(){
  pinMode(Tx, OUTPUT);                                                    // Configure Tx as OUTPUT (Transmitter)
  pinMode(Rx, INPUT);                                                     // Configure Rx as INPUT (Reciever)

  Bluetooth.begin(9600);                                                 // Set Bluetooth baud rate to default baud rate 38400
  Bluetooth.print("\r\n+STWMOD=0\r\n");                                   // Set the Bluetooth to work in slave mode
  Bluetooth.print("\r\n+STNA=Luma Mini\r\n");                             // Set Bluetooth name to Luma Mini
  Bluetooth.print("\r\n+STOAUT=1\r\n");                                   // Permit paired device to connect
  Bluetooth.print("\r\n+STAUTO=0\r\n");                                   // Auto-connection should be forbidden here
  delay(2000);
  Bluetooth.print("\r\n+INQ=1\r\n");                                      // Make this Bluetooth Slave inquirable
  Serial.println("The slave Bluetooth is inquirable!");
  delay(2000);
  Bluetooth.flush();
}

void TimerOneSetup(){
  Timer1.initialize(1000000);                                             // Initialize Timer One for an overflow exactly every 1 second
  Timer1.attachInterrupt(interrupt1);                                     // Open the Timer One loop
} 

void fourtyLeds(){                                                        // Show the 40 Leds version of the Luma Mini
  for(int i = 5; i <= 8; i++){
    digitalWrite(i, LOW);
  }
}

void thirtyLeds(){                                                        // Show the 30 Leds version of the Luma Mini
  digitalWrite(5, HIGH);
  digitalWrite(6, LOW);
  digitalWrite(7, LOW);
  digitalWrite(8, LOW);
}

void twentyLeds(){                                                        // Show the 20 Leds version of the Luma Mini
  digitalWrite(5, HIGH);
  digitalWrite(6, HIGH);
  digitalWrite(7, LOW);
  digitalWrite(8, HIGH);
}

void twelveLeds(){                                                        // Show the 12 Leds version of the Luma Mini
  for (int i = 5; i <= 8; i++){
    digitalWrite(i, HIGH);
  }
}
#包括
#包括
#定义RX2
#定义Tx 3
#定义秒数4
char serialData;//串行数据存储器
int counter 1;//溢出内存
int action;//动作触发器
int once=0;//只跑一次
软件串行蓝牙(Rx、Tx);
无效设置(){
pinMode(发送,输出);//将发送配置为输出(变送器)
pinMode(接收、输入);
延迟(1000);
蓝牙开始(9600);
序列号。开始(1200);
延迟(1000);
串行打印(“蓝牙就绪”);
Bluetooth.flush();
TimerOneSetup();//运行计时器1的安装程序
对于(inti=5;i3){//在运行所有操作后重置操作触发器
动作=0;
}
}
void loop(){//无限循环
if(Serial.available()){//等待从本地设备接收到的数据
serialData=Serial.read();//将接收到的数据放入内存
串行打印(“从本地设备接收的数据:”);
Serial.println(serialData);
}
if(Bluetooth.available()){//等待从蓝牙设备接收到的数据
serialData=Bluetooth.read();//将接收到的数据放入内存
串行打印(“从蓝牙设备接收的数据:”);
串口打印(串口数据);
}
如果(once==0){//此脚本将只运行一次
serialData='e';//启动时自动打开开关
once++;//进入下一阶段,该阶段可能只运行一次
}
开关(serialData){//对开关的状态执行操作
案例“a”:
fourtyLeds();//显示Luma Mini的40个LED版本
打破
案例“b”:
thirtyLeds();//显示30个LED版本的Luma Mini
打破
案例“c”:
twentyLeds();//显示Luma Mini的20个LED版本
打破
案例“d”:
twelveLeds();//显示Luma Mini的12个LED版本
打破
案例“e”:
而(serialData=='e'){//保持自动更改Luma Mini的不同Led版本
开关(动作){
案例0://等待操作触发器触发第一个操作
fourtyLeds();//显示Luma Mini的40个LED版本
打破
案例1://等待操作触发器触发第二个操作
twelveLeds();//显示Luma Mini的12个LED版本
打破
案例2://等待操作触发器触发第三个操作
twentyLeds();//显示Luma Mini的20个LED版本
打破
案例4://等待操作触发器触发第四个操作
thirtyLeds();//显示30个LED版本的Luma Mini
中断;}
如果(Serial.read()=='f'){//等待从本地设备接收到的数据
serialData=Serial.read();//将接收到的数据放入内存
串行打印(“从本地设备接收的数据:”);
Serial.println(serialData);
}
如果(Bluetooth.read()=='f'){//等待从蓝牙设备接收到的数据
serialData=Bluetooth.read();//将接收到的数据放入内存
串行打印(“从蓝牙设备接收的数据:”);
Serial.println(serialData);
}
打破
}
}
}
void BluetoothSetup(){
pinMode(发送,输出);//将发送配置为输出(变送器)
pinMode(接收,输入);//将接收配置为输入(接收器)
Bluetooth.begin(9600);//将Bluetooth波特率设置为默认波特率38400
Bluetooth.print(“\r\n+STWMOD=0\r\n”);//将Bluetooth设置为在从属模式下工作
Bluetooth.print(“\r\n+STNA=Luma Mini\r\n”);//将Bluetooth名称设置为Luma Mini
Bluetooth.print(“\r\n+STOAUT=1\r\n”);//允许配对设备连接
Bluetooth.print(“\r\n+stato=0\r\n”);//此处应禁止自动连接
package com.exercise.androidanimbuttons;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.IntentFilter;
import android.widget.Toast;
import android.bluetooth.BluetoothSocket;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import java.io.IOException;
import java.io.InputStream;
import java.util.UUID;
import java.util.Set;
import android.os.Handler;

public class BlueTooth extends vars {

private Set<BluetoothDevice> pairedDevices;
String address = null;
private ProgressDialog progress = null;
BluetoothAdapter myBluetooth = null;
BluetoothSocket btSocket = null;
InputStream mmInStream = null;
private Handler myHandler = new Handler();
byte[] buffer = new byte[25];
int readBytes;
files filesI = new files();
Handler btH = new Handler();
static final UUID myUUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
private SingBroadcastReceiver mReceiver;
Runnable btSearch;

void stopDiscovery() {
    if (myBluetooth.isDiscovering()){
        myBluetooth.cancelDiscovery();
    }
}

void findCurrentBT() {
    if (!myBluetooth.isEnabled()){
        Intent enableBT = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
        startActivityForResult(enableBT, 0xDEADBEEF);
    }
    if (myBluetooth.isDiscovering()){
        myBluetooth.cancelDiscovery();
    }
    closeProgress();
    progress = ProgressDialog.show(BlueTooth.this, "Searching for headband...",
            "MAKE  SURE  THE  HEADBAND  IS  TURNED  ON.");
    progress.setCanceledOnTouchOutside(true);
    myBluetooth.startDiscovery();
    mReceiver = new SingBroadcastReceiver();
    IntentFilter ifilter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
    this.registerReceiver(mReceiver, ifilter);
    checkSearch();
}

private class SingBroadcastReceiver extends BroadcastReceiver {

    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        if (BluetoothDevice.ACTION_FOUND.equals(action)) {
            BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
            String derp = device.getName() + " - " + device.getAddress();
            ta(derp);
            Toast.makeText(context, derp, Toast.LENGTH_LONG);
            if ((device.getName() != null) &&
               (device.getName().indexOf("HC-06") == 0) &&
               (device.getName().length() == 5))
            {
                myBluetooth.cancelDiscovery();
                address = device.getAddress();
                new ConnectBT().execute();
            }
        }
    }
}

private Runnable readBT = new Runnable() {
    public void run() {
        int i;
        int twoByte = 0;
        short high = 0, low = 0;
        try {
            if (mmInStream.available() > 3) {
                cnt = 0;
                readBytes = mmInStream.read(buffer);
                String S = "";
                for (i = 0; i < 2; i++)
                    S += String.format("%03d", buffer[i] & 0xFF)+",   ";
                high = (short)(buffer[3] & 0xFF);
                low = (short)(buffer[2] & 0xFF);
                twoByte = ((high << 8) | low);
                S += String.format("%03d", twoByte) + "\r\n";
                filesI.writeALine("nights","data12.txt",S);
                ta(S);
            }
        } catch (IOException e) {
            ta("err:2 " + e.toString());
        }
        if (btSocket.isConnected())
            myHandler.postDelayed(this, 100);
    }
};

public void btConnect() {
    Disconnect();
    findCurrentBT();
}

public void btOn() {
    turnOnLed();
}

public void btOff() { turnOffLed(); }

public void btDisconnect() { Disconnect(); }

private void Disconnect()
{
    if (btSocket!=null)
    {
        try
        {
            btSocket.close();
        }
        catch (IOException e)
        { msg("Bluetooth Disconnect Error");}
    }
}

private void turnOffLed()
{
    if (btSocket!=null)
    {
        try
        {
            btSocket.getOutputStream().write("TF".toString().getBytes());
        }
        catch (IOException e)
        {
            msg("Error");
        }
    }
}

private void turnOnLed()
{
    int len;
    byte[] buffer = new byte[400];
    if (btSocket!=null)
    {
        try
        {
            btSocket.getOutputStream().write("TO".toString().getBytes());
            len = btSocket.getInputStream().available();
            btSocket.getInputStream().read(buffer,0,len);
         }
        catch (IOException e)
        {
            msg("Error");
        }
    }
}

private void msg(String s)
{
    Toast.makeText(getApplicationContext(),s,Toast.LENGTH_LONG).show();
}

void closeProgress() {
    if (progress != null)
        progress.dismiss();
}

private class ConnectBT extends AsyncTask<Void, Void, Void>
{
    @Override
    protected void onPreExecute()
    {
        closeProgress();
        progress = ProgressDialog.show(BlueTooth.this, "Connecting to headband...",
            "");
        progress.setCanceledOnTouchOutside(true);
    }

    @Override
    protected Void doInBackground(Void... devices)
    {
        try
        {
            if (btSocket == null || (!btSocket.isConnected()))
            {
                BluetoothDevice dispositivo = myBluetooth.getRemoteDevice(address);
                btSocket = dispositivo.createInsecureRfcommSocketToServiceRecord(myUUID);
                BluetoothAdapter.getDefaultAdapter().cancelDiscovery();
                btSocket.connect();
            }
        }
        catch (IOException e) { }
        return null;
    }

    @Override
    protected void onPostExecute(Void result)
    {
        super.onPostExecute(result);
        if (!btSocket.isConnected())
        {
            msg("Connection Failed.    Is the headband turned on?");
        }
        else
        {
            msg("Connected.");
            try {
                mmInStream = btSocket.getInputStream();
                myHandler.postDelayed(readBT, 1000);

            } catch (IOException e) {
                ta("err:1 " + e.toString());
            }
        }
        closeProgress();
    }
}

    int cnt = 0;
void checkSearch() {
    if (btSearch != null)
        return;
    btSearch = new Runnable(){@Override public void run(){
        if ((btSocket != null) && (btSocket.isConnected())) {
            cnt--;
            if (cnt < -10) {
                cnt = 0;
                btConnect();
            }
        } else if (myBluetooth.isDiscovering()) {
            cnt++;
        }
        btH.postDelayed(this, 1000);
        fa(cnt);
    }};
    btH.postDelayed(btSearch,1000);
}

}
byte mini [4];
int battery;
unsigned long mill = millis();
byte moveCnt = 1;
int minuteCnt = 0;
int lastMove = 0;
int moveA, moveB, moveC, LMoveA, LMoveB, LMoveC, totMove, eyes, LEyes, totEyes;
int moveUpA = 0;
int moveDnA = 1000;
int moveUpB = 0;
int moveDnB = 1000;
int moveUpC = 0;
int moveDnC = 1000;

#include <SoftwareSerial.h>
SoftwareSerial mySerial(3, 5); // RX, TX

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

void loop()
{
if (millis() > mill)
{
mill += 100;
minuteCnt++;

// *** EYES ***
eyes = analogRead(A6);
totEyes += abs(eyes-LEyes);
LEyes = eyes;

// *** MOVEMENT ***              --KEEP--   moveA = max(0,analogRead(A1) >> 2);
moveA = analogRead(A0);
moveB = analogRead(A1);
moveC = analogRead(A2);
totMove += abs(moveA-LMoveA) + abs(moveB-LMoveB) + abs(moveC-LMoveC);
LMoveA = moveA; LMoveB = moveB; LMoveC = moveC;

// *** SEND SECOND ***
if (minuteCnt >= 10)
{
  minuteCnt = 0;

  // *** BATTERY ***
  battery = analogRead(A5);    // battery
  mini[2] = (battery & 0xff);  // battery low byte
  mini[3] = ((battery >> 8) & 0xff); // battery high byte

  // *** EYES ***
  mini[0] = min(max(0,totEyes-10),255);
  totEyes = 0;

  // *** MOVEMENT ***
  mini[1] = min(max(0,totMove-30),255);
  totMove = 0;
  Serial.print(mini[0]);
  Serial.print(" ");
  Serial.print(mini[1]);
  Serial.print(" ");
  Serial.print(mini[2]);
  Serial.print(" ");
  Serial.println(mini[3]);
  mySerial.write(mini,4);
}
}
}