微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决在 Processing 3.0 中将用户输入文本框中的值转换为用于 port.write() 到 Arduino 的字符串数组

我正在处理处理和 arduino 接口。在某种程度上,我是成功的并且使用 Processing 3.0 作为用户界面我能够向 arduino 发送命令。但是,我只能发送一个值,而 arduino 会同时为所有 3 个电机在该特定值上运行步进电机。 但是,我想以不同的速度控制所有 3 个电机。为此,我需要将 3 个不同的值从 Processing 转换为 Arduino。 我打算使用一个数组,然后在 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,20)); 
  
  cp5.addTextfield("Motor 3")
  .setPosition(750,300)
      .setSize(80,50) 
      .setFont(font)
      .setColorBackground(color(50,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,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,','); 

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。