报错'D5' was not declared in this scope,如何解决?-Arduino中文社区 - Powered by Discuz!

Arduino中文社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 3631|回复: 5

[已解决] 报错'D5' was not declared in this scope,如何解决?

[复制链接]
发表于 2020-8-23 10:02 | 显示全部楼层 |阅读模式
#define BLINKER_WIFI

#include <Blinker.h>

char auth[] = "15991537557UF";
char ssid[] = "sxbctvnet-张军";
char pswd[] = "13689216174";

//新建组件对象
BlinkerButton Button1("btn-a");    //前进
BlinkerButton Button2("btn-1");    //左转
BlinkerButton Button3("btn-r");    //右转
BlinkerButton Button4("btn-b");    //后退
BlinkerButton Button5("btn-t");    //停车
BlinkerButton Button6("num-abc");
BlinkerButton Button7("btn-q");
BlinkerButton Button8("btn-h");
BlinkerButton Button9("btn-y");
BlinkerButton Button10("btn-z");
int counter = 0;

#define IN1                D5          //左转引脚
#define IN2                D6           //左转引脚调值
#define IN3                D7           //右转引脚
#define IN4                D8           //右转引脚调值
#define TIME_TAP           100           //延时参数
void blinker_car_init()
{
  pinMode(IN1,OUTPUT);
  pinMode(IN2,OUTPUT);
  pinMode(IN3,OUTPUT);
  pinMode(IN4,OUTPUT);
  digitalWrite(IN1,LOW);
  digitalWrite(IN2,LOW);
  digitalWrite(IN3,LOW);
  digitalWrite(IN4,LOW);
}
//按下按键会立即执行该函数
void button1_callback(const String & state)
{
  BLINKER_LOG("get button state: ", state);
  if(state=="tap")
  {
    digitalWrite(IN1,HIGH);
    digitalWrite(IN3,HIGH);
      delay(TIME_TAP);
    digitalWrite(IN1,LOW);    //右轮前进
    digitalWrite(IN3,LOW);    //左轮前进
  }
  if(state=="press")
  {
    digitalWrite(IN1,HIGH);
    digitalWrite(IN3,HIGH);
  }
  if(state=="pressup")
  {
    digitalWrite(IN1,LOW);     //右轮前进
    digitalWrite(IN3,LOW);     //左轮前进
  }
}
void button2_callback(const String & state)
{
  BLINKER_LOG("get button state: ", state);
  if(state=="tap")
  {
    digitalWrite(IN1,HIGH);
      delay(180);
    digitalWrite(IN1,LOW);   //右轮前进
    digitalWrite(IN2,LOW);
    digitalWrite(IN3,LOW);
    digitalWrite(IN4,LOW);   //左轮不动
  }
}
void button3_callback(const String & state)
{
  BLINKER_LOG("get button state: ", state);
  if(state=="tap")
  {
    digitalWrite(IN3,HIGH);
      delay(180);
    digitalWrite(IN1,LOW);   
    digitalWrite(IN3,LOW);
    digitalWrite(IN2,LOW);   //右轮不动
    digitalWrite(IN4,LOW);   //左轮前进
  }
  if(state=="press")
  {
    digitalWrite(IN3,HIGH);
  }
  if(state=="pressup")
  {
    digitalWrite(IN1,LOW);     
    digitalWrite(IN2,LOW);     //右轮不动
    digitalWrite(IN3,LOW);     
    digitalWrite(IN4,LOW);     //左轮前进
  }
}
void button4_callback(const String & state)
{
  BLINKER_LOG("get button state: ", state);
  if(state=="tap")
  {
    digitalWrite(IN2,HIGH);
    digitalWrite(IN4,HIGH);
      delay(TIME_TAP);
    digitalWrite(IN2,LOW);   //右轮不动
    digitalWrite(IN4,LOW);   //左轮前进
  }
  if(state=="press")
  {
    digitalWrite(IN2,HIGH);  //右轮后退
    digitalWrite(IN4,HIGH);  //左轮后退
  }
  if(state=="pressup")
  {
    digitalWrite(IN2,LOW);     
    digitalWrite(IN4,LOW);     //右轮不动
    digitalWrite(IN3,LOW);     
    digitalWrite(IN1,LOW);     //左轮前进
  }
}
void button5_callback(const String & state)
{
  BLINKER_LOG("get button state: ", state);
  if(state=="tap")
  {
    digitalWrite(IN1,LOW);
    digitalWrite(IN2,LOW);
    digitalWrite(IN4,LOW);   
    digitalWrite(IN3,LOW);   
  }
  if(state=="press")
  {
    digitalWrite(IN1,LOW);
    digitalWrite(IN2,LOW);
    digitalWrite(IN4,LOW);
    digitalWrite(IN3,LOW);
  }
  if(state=="pressup")
  {
    digitalWrite(IN1,LOW);
    digitalWrite(IN2,LOW);
    digitalWrite(IN4,LOW);   
    digitalWrite(IN3,LOW);
  }
}
void button7_callback(const String & state)
{
  BLINKER_LOG("get button state: ", state);
  if(state=="tap")
  {
    digitalWrite(IN1,HIGH);
    digitalWrite(IN3,HIGH);
    digitalWrite(IN2,LOW);   
    digitalWrite(IN4,LOW);   
  }
}
void button8_callback(const String & state)
{
  BLINKER_LOG("get button state: ", state);
  if(state=="tap")
  {
    digitalWrite(IN2,HIGH);
    digitalWrite(IN4,HIGH);
    digitalWrite(IN1,LOW);   
    digitalWrite(IN3,LOW);   
  }
}
void button9_callback(const String & state)
{
  BLINKER_LOG("get button state: ", state);
  if(state=="tap")
  {
    analogWrite(IN1,1023);
    analogWrite(IN3,500);
    delay(500);
    digitalWrite(IN1,LOW);
    digitalWrite(IN3,LOW);
  }
  if(state=="press")
  {
    analogWrite(IN1,1023);
    analogWrite(IN3,500);

  }
  if(state=="pressup")
  {
    digitalWrite(IN1,LOW);
    digitalWrite(IN2,LOW);
    digitalWrite(IN4,LOW);   
    digitalWrite(IN3,LOW);
  }
}
void button10_callback(const String & state)
{
  BLINKER_LOG("get button state: ", state);
  if(state=="tap")
  {
    analogWrite(IN3,1023);
    analogWrite(IN1,500);
    delay(500);
    digitalWrite(IN1,LOW);
    digitalWrite(IN3,LOW);
  }
  if(state=="press")
  {
    analogWrite(IN3,1023);
    analogWrite(IN1,500);

  }
  if(state=="pressup")
  {
    digitalWrite(IN1,LOW);
    digitalWrite(IN2,LOW);
    digitalWrite(IN4,LOW);   
    digitalWrite(IN3,LOW);
  }
}
//如果未绑定的组件被触发,则会执行其中内容
void dataRead(const String & data)
{
  BLINKER_LOG("Blinker readString: ", data);
  Number6.print(counter);
}
void setup(){
  Serial.begin(115200);
  BLINKER_DEBUG.stream(Serial);

  //初始化有LED的IO
  blinker _car_init();
  pinMode(LED_BULLTIN,OUTPUT);

  //初始化blinker
  Blinker.begin(auth, ssid, pswd);
  Blinker.attachData(dataRead);
  Button1.attach(button1_callback);
  Button2.attach(button1_callback);
  Button3.attach(button1_callback);
  Button4.attach(button1_callback);
  Button5.attach(button1_callback);
  Button6.attach(button1_callback);
  Button7.attach(button1_callback);
  Button8.attach(button1_callback);
  Button9.attach(button1_callback);
  Button10.attach(button1_callback);
}
void loop()
{
  Blinker.run();
}


发表于 2020-8-23 10:56 | 显示全部楼层
写GPIO对应的数字编号,不要加“D”
 楼主| 发表于 2020-9-15 18:49 | 显示全部楼层
奈何col 发表于 2020-8-23 10:56
写GPIO对应的数字编号,不要加“D”

用的是esp8266,他对应的·gpio口就是D0-D8

点评

D开头的不是GPIO编号,找到实际的GPIO编号,然后直接写就行了  详情 回复 发表于 2020-9-15 19:38
发表于 2020-9-15 19:38 | 显示全部楼层
天涯何处无芳草 发表于 2020-9-15 18:49
用的是esp8266,他对应的·gpio口就是D0-D8

D开头的不是GPIO编号,找到实际的GPIO编号,然后直接写就行了
发表于 2020-9-15 19:49 | 显示全部楼层
开发板型号不对?
试试选WeMos D1
发表于 2022-5-23 12:59 | 显示全部楼层
我也碰到这个问题了,楼主怎么解决的啊
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|Archiver|手机版|Arduino中文社区

GMT+8, 2025-1-1 20:50 , Processed in 0.096521 second(s), 17 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表