0
我正嘗試通過串口工作來構建一個Arduino聊天殭屍工具。它將這些東西發送到我的Mac。我有很多問題,錯誤等等。有人可以請指點我正確的方向嗎?這是我的代碼到目前爲止。我知道這並不完美,但這就是爲什麼我要學習。與Arduino聊天殭屍工具
//error responses from 1 to 10
void error11() {
Serial.println("What do you mean");
}
void error10() {
Serial.println("I dont understand");
}
void error9() {
Serial.println("My Programmer didnt give me a response for that please ask another question");
}
void error8() {
Serial.println("?????");
}
void error7() {
Serial.println("Huh??");
}
void error6() {
Serial.println("Can not compute");
}
void error5() {
Serial.println("Can you say that again");
}
void error4() {
Serial.println("Im sorry what");
}
void error3() {
Serial.println("Hmmm what");
}
void error2() {
Serial.println("What");
}
void error1() {
Serial.println("Sorry What Did You Say");
}
// greeting responses from 1 to 10
void greeting10() {
Serial.println("What can i do for you");
}
void greeting9() {
Serial.println("Yo");
}
void greeting8() {
Serial.println("Hello Master");
}
void greeting7() {
Serial.println("Greetings!!");
}
void greeting6() {
Serial.println("Sup");
}
void greeting5() {
Serial.println("Hiya");
}
void greeting4() {
Serial.println("hi");
}
void greeting3() {
Serial.println("How is it going");
}
void greeting2() {
Serial.println("What's up");
}
void greeting1() {
Serial.println("hello Friend");
}
String stringRead;
long randNumber;
void setup() {
Serial.begin(9600);
}
void loop() {
randNumber = random(4);
if (Serial.available()) {
stringRead = Serial.readStringUntil('\n');
if(stringRead =="hello","Hello","HELLO") {
greeting8();
if (Serial.available()) {
stringRead = Serial.readStringUntil('\n');
if(stringRead =="hi","Hi","HI") {
greeting4();
}
} else {
error3();
}
}
}
}
我真的希望能夠從1到10有一個隨機響應,但我無法讓它工作。任何幫助將不勝感激。