我遇到了一個Arduino程序的小問題,我試圖通過串行連接來讀取處理中發送的命令。處理過程應通過串行連接向Arduino發送「H」或「L」。這個值在我的程序中存儲爲char,但是當我嘗試執行Serial.write(「Value:%c」,val)時,出現「從'const char *'無效轉換爲'const uint8_t *'」錯誤。如果有人能夠幫助我解決這個問題,那就太好了。我真的需要弄清楚這個值是什麼,所以我可以重寫我的程序。謝謝!無效的從'const char *'轉換爲'const uint8_t *'
代碼如下規定:
char val; // variable to receive data from the serial port
int ledpin = 8; // LED connected to pin 48 (on-board LED)
void setup() {
pinMode(ledpin, OUTPUT); // pin 48 (on-board LED) as OUTPUT
Serial.begin(9600); // start serial communication at 9600bps
}
void loop() {
while (Serial.available()>0){
val=Serial.read();
}
//Serial.write("Value: %c",(char)val);
if(val == 'H') // if 'H' was received
{
Serial.write("Setting Value to High \n");
digitalWrite(ledpin, HIGH); // turn ON the LED
} else {
Serial.write("Setting Value to Low \n");
digitalWrite(ledpin, LOW); // otherwise turn it OFF
}
Serial.flush();
delay(100); // wait 100ms for next reading
}