Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.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
Arrays 在Processing 3.0中将用户输入(文本框)中的值强制转换为port.write()到Arduino的字符串数组_Arrays_Interface_Arduino_Processing - Fatal编程技术网

Arrays 在Processing 3.0中将用户输入(文本框)中的值强制转换为port.write()到Arduino的字符串数组

Arrays 在Processing 3.0中将用户输入(文本框)中的值强制转换为port.write()到Arduino的字符串数组,arrays,interface,arduino,processing,Arrays,Interface,Arduino,Processing,我正在处理和arduino接口。在某种程度上,我是成功的,使用Processing 3.0作为用户界面,我能够向arduino发送命令。然而,我只能发送一个值,arduino运行一个步进电机,在这个特定的位置同时运行所有3个电机。 但是,我想控制所有3个不同速度的电机。为此,我需要从Processing到Arduino转换3个不同的值。 我打算使用一个数组,然后在arduino中拆分该数组 我的处理代码如下: import controlP5.*; import processing.seria

我正在处理和arduino接口。在某种程度上,我是成功的,使用Processing 3.0作为用户界面,我能够向arduino发送命令。然而,我只能发送一个值,arduino运行一个步进电机,在这个特定的位置同时运行所有3个电机。 但是,我想控制所有3个不同速度的电机。为此,我需要从Processing到Arduino转换3个不同的值。 我打算使用一个数组,然后在arduino中拆分该数组

我的处理代码如下:

import controlP5.*;
import processing.serial.*; // when we add any value in GUI it will go the the arduino through serial
Serial port;
ControlP5 cp5;
PFont font; //for enlarging the font size
String textA;
String textB;
String textC;
String q;

void setup(){
  size(900,500); //(width,height)  
  
  printArray(Serial.list()); //prints all available Serial port
   //port = new Serial(this,"COM5",115200);
                                                                                    //lets add button to the window
  cp5 = new ControlP5(this);
  font = createFont("Ebrima bold",20); // custom fonts for button and title
  
  cp5.addTextfield("Motor 1").setPosition(150,300).setSize(80,50).setAutoClear(false)
     .setFont(font)
     .setColorBackground(color(50, 113, 20));
     
     //Processing text input box
     //textbox1.draw();
    
  
  cp5.addTextfield("Motor 2") 
  .setPosition(450,300) 
       .setSize(80,50) 
       .setFont(font)
       .setColorBackground(color(50, 113, 20)); 
  
  cp5.addTextfield("Motor 3")
  .setPosition(750,300)
      .setSize(80,50) 
      .setFont(font)
      .setColorBackground(color(50, 113, 20));
          
   cp5.addBang("Submit").setPosition(450,400).setSize(100,50);
    
}

void draw(){
     background(10,100,80) ; //background colour (0 to 255) or (r,b,g)
       
      fill(250,55,0); //(text colour(r,g,b) 
        //Line 5
        fill(0,0,0); //(text colour(r,g,b)
       font = createFont("Ebrima",18);
       textFont(font);
        text(" Please Choose Stepper Motors Speed Below:",150,250);      
       
  }
void Submit () {
  textA=cp5.get(Textfield.class,"Motor 1").getText();
  textB=cp5.get(Textfield.class,"Motor 2").getText();
  textC=cp5.get(Textfield.class,"Motor 3").getText();
  
 q = textA+textB+textC;
 String[] data1 = textA;
String data = concat(textA,textB,textC); 
String data = join(data, ',') 

port.write(data);
}
但是,我无法从用户输入中创建一个可以发送到串行端口的阵列


需要这方面的帮助吗。

我是一个绝对的新手,但也许下面是它的工作原理:

String[] data1 = new String[3];
data1[0]=textA;
data1[1]=textB;
data1[2]=textC;
String data = join(data1, ','); 

通过本教程中的一点努力,我能够制作一系列数字。如果有人有在Arduino中阅读字符串数组的经验或教程,请与我们分享。谢谢你,比尔。我确实修改了上面教程中的代码,但是字符串的连接是不同的。所以我会试试这个,让你知道。