2016-08-18 280 views
0

我從YouTube視頻複製腳本,因爲沒有下載鏈接到腳本,但現在我總是收到相同的錯誤消息,而我不知道該怎麼辦。你可以幫幫我嗎?對於數組下標,無效類型'uint8_t {aka unsigned char} [int]'

這是我的代碼:

#include <VirtualWire.h> 
 

 
int ledPassive = 5; 
 
int ledActive = 7; 
 
int motor = 8; 
 

 
void setup() { 
 
    // put your setup code here, to run once: 
 
pinMode(ledPassive,OUTPUT); 
 
pinMode(ledActive,OUTPUT); 
 
pinMode(motor,OUTPUT); 
 
vw_set_ptt_inverted(true); 
 
vw_set_rx_pin(12); 
 
vw_setup(4000); 
 
vw_rx_start(); 
 

 
} 
 

 
void loop() 
 
{ 
 
    
 
digitalWrite(ledPassive,HIGH); 
 
digitalWrite(motor,LOW); 
 
digitalWrite(ledActive,LOW); 
 
uint8_t buf(VW_MAX_MESSAGE_LEN); 
 
uint8_t buflen = VW_MAX_MESSAGE_LEN; 
 

 
if (vw_get_message(buf, &buflen)) { 
 
    if (buf[0]=='X'){ 
 
    digitalWrite(ledPassive,LOW); 
 
    for (int i=0;i<10;i++){ 
 
     digitalWrite(motor,LOW); 
 
     digitalWrite(ledActive,HIGH); 
 
     delay(200); 
 
     digitalWrite(motor,HIGH); 
 
     digitalWrite(ledActive,LOW); 
 
     delay(200); 
 
    } 
 
} 
 
    else if (buf[0]!='x'){ 
 
    digitalWrite(ledPassive,HIGH); 
 
    } 
 
} 
 
}

這是錯誤消息:

Arduino: 1.6.10 (Windows 10), Board:"Arduino Nano, ATmega328" 
 

 
In function 'void loop()': 
 

 
sketch_aug18e_self_made:29: error: invalid types 'uint8_t {aka unsigned char}[int]' for array subscript 
 

 
    if (buf[0]=='X'){ 
 

 
      ^
 

 
sketch_aug18e_self_made:40: error: invalid types 'uint8_t {aka unsigned char}[int]' for array subscript 
 

 
    else if (buf[0]!='x'){ 
 

 
       ^
 

 
exit status 1 
 
invalid types 'uint8_t {aka unsigned char}[int]' for array subscript 
 

 
This report would have more information with 
 
"Show verbose output during compilation" 
 
option enabled in File -> Preferences.

很抱歉的髒話我是荷蘭人並沒有那麼在英語

很好
+0

嘗試替換'uint8_t buf(VW_MAX_MESSAGE_LEN);' 'uint8_t buf [VW_MAX_MESSAGE_LEN];'' (注意方括號) –

+0

謝謝,它的工作原理! – Simon

回答

1

嘗試

uint8_t buf[VW_MAX_MESSAGE_LEN];

你正在使用的語法不正確的聲明數組替換

uint8_t buf(VW_MAX_MESSAGE_LEN);

相關問題