Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我想知道如何将Android中的5个字符串发送到Arduino以存储在变量中?_Android_Arduino - Fatal编程技术网

我想知道如何将Android中的5个字符串发送到Arduino以存储在变量中?

我想知道如何将Android中的5个字符串发送到Arduino以存储在变量中?,android,arduino,Android,Arduino,我使用了Amarino在Android上从5个EditText接收5个字符串,然后发送到Arduino //Code to send a String. One of five Strings. Amarino.sendDataToArduino(MainActivity.this,"HC-05",'a',name); 在Arduino中,我为保存在变量中的每个字符串创建了函数。但我不能通过考试。有一个错误消息void值不能被忽略,因为它应该被忽略 //Arduino code. I ta

我使用了Amarino在Android上从5个EditText接收5个字符串,然后发送到Arduino

//Code to send a String.  One of five Strings.
Amarino.sendDataToArduino(MainActivity.this,"HC-05",'a',name);
在Arduino中,我为保存在变量中的每个字符串创建了函数。但我不能通过考试。有一个错误消息void值不能被忽略,因为它应该被忽略

//Arduino code.  I take part of custom function code that relate Meetandroid.
void getUsername(byte flag, byte numOfValues)
{
  // first we need to know how long the string was in order to prepare an array 
  // big enough to hold it.
  // you should know that: (length == 'length of string sent from Android' + 1)
  // due to the '\0' null char added in Arduino
  int length = meetAndroid.stringLength();

  // define an array with the appropriate size which will store the string
  char data[length];

  // tell MeetAndroid to put the string into your prepared array
  //Can't compile Here
  username = meetAndroid.getString(data);
}
我还尝试发送字符串数组。Amarino中有一个函数,但我找不到接收函数。我不知道我会错过什么。如何解决这个问题

//data is array of String in Andriod
Amarino.sendDataToArduino(MainActivity.this,"HC-05",'a',data);
meetAndroid.getStringdata没有返回值。因此,您不能将其分配给用户名

改为:

char data [] = new char[length];

meetAndroid.getString(data);

String username = data.toString();

return username; // and change function return type to String

您确定字节数据[]=新字节[长度];是不是更合适?

我想你认为它是Java,但它是Arduino C。我看过一本书。C语言中的新指针。Arduino C中没有toString,并且relate函数被迫在自定义函数中使用void。对于字节,我想我要存储像name这样的东西,我想应该是字母而不是数字。
char data [] = new char[length];

meetAndroid.getString(data);

String username = data.toString();

return username; // and change function return type to String