数组下标的无效类型 'uint8_t {aka unsigned char}[int]'
invalid types 'uint8_t {aka unsigned char}[int]' for array subscript
我从 YouTube 视频复制了一个脚本,因为没有下载 link 脚本,但现在我总是收到相同的错误消息,我不知道该怎么办。你能帮帮我吗?
这是我的代码:
#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.
抱歉语言不好,我是荷兰人,英语不是很好
尝试替换
uint8_t buf(VW_MAX_MESSAGE_LEN);
和
uint8_t buf[VW_MAX_MESSAGE_LEN];
您使用了不正确的语法来声明数组。
我从 YouTube 视频复制了一个脚本,因为没有下载 link 脚本,但现在我总是收到相同的错误消息,我不知道该怎么办。你能帮帮我吗?
这是我的代码:
#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.
抱歉语言不好,我是荷兰人,英语不是很好
尝试替换
uint8_t buf(VW_MAX_MESSAGE_LEN);
和
uint8_t buf[VW_MAX_MESSAGE_LEN];
您使用了不正确的语法来声明数组。