【问题标题】:How to print an string array generated in processing to Arduino如何将处理中生成的字符串数组打印到 Arduino
【发布时间】:2019-01-30 18:56:46
【问题描述】:

我正在尝试将处理过程中生成的字符串发送到 Arduino,以便可以将其打印在 LCD 屏幕上。使用此方法,LCD 上不会出现任何内容。我尝试了各种方法,根据我的研究,我正在尝试的方法是这样的:

#include <LiquidCrystal.h>

char inData[9]; // Allocate some space for the string
char inChar=-1; // Where to store the character read
byte index = 0; // Index into array; where to store the character

const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);


void setup() {
lcd.begin(16, 2);
lcd.setCursor(0,1);
Serial.begin(9600); // Start serial communication at 9600 bps
}

 char Comp(char* This) {
while (Serial.available() > 0) // Don't read unless
                               // there you know there is data
{
    if(index < 8) // One less than the size of the array
    {
        inChar = Serial.read(); // Read a character
        inData[index] = inChar; // Store it
        index++; // Increment where to write next
        inData[index] = '\0'; // Null terminate the string
    }
}

if (strcmp(inData,This)  == 0) {
    for (int i=0;i<8;i++) {
        inData[i]=0;
    }
    index=0;
    return(0);
}
else {
    return(1);
}
}

void loop() 
{
if(Serial.available() > 0){
lcd.print(inData[index]);
}
}

【问题讨论】:

标签: string arduino processing


【解决方案1】:

我不确定我的 anwser,但可能是因为 indata 在打印之前就被终止了。虽然我对我的回答感到不安,但希望它有所帮助。

终止:

    inData[index] = '\0'; // Null terminate the string

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-09-05
    • 1970-01-01
    • 1970-01-01
    • 2021-03-28
    • 2011-01-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多