blinker没有多点触控功能对吗????
我这几天一直研究esp8266小车,通过blinker库进行控制,商家发送的程序只能单功能控制,点击向前时小车向前,但是当点击向前时再点击向左,小车并不会在前进的过程中向左偏移,而是停止前进再向左。我想实现的功能是小车前进的过程中,点击向左,小车就会变前进变向左,
我刚开始想对返回的数据进行判断,发现绑定的功能函数只能绑定一个按键,所以只能一个一个返回再记录,所以写了一下,大致原理是返回后用数字记录
使用串口监视器,我发现,在按住前进b2的时候,再按住b4并不会触发b4的状态响应,故得出结果,blinker软件并不支持多点触控
void button2_callback(const String &state)//前进
{
if (state == "press")//按下
{
b2=1;
}
else if (state == "pressup")//松开
{
b2=2;
}
}
void blinker_car_init()
{
//1-4号引脚设置为输出模式
pinMode(16, OUTPUT);//
pinMode(5, OUTPUT);//
pinMode(4, OUTPUT);//
pinMode(2, OUTPUT);//
}
void setup()//初始化
{
digitalWrite(D0, HIGH);
digitalWrite(D1, HIGH);
digitalWrite(D2, HIGH);
digitalWrite(D4, HIGH);
analogWriteRange(100);
analogWriteFreq(50);
//analogWrite(D2, 50);//0-10050
//初始化小车参数
blinker_car_init();
Serial.begin(9600);
Serial.println("Please input serial data.");
//按钮绑定
Button2.attach(button2_callback);
Button4.attach(button4_callback);
Button5.attach(button5_callback);
Button6.attach(button6_callback);
Button8.attach(button8_callback);
Slider0.attach(slider0_callback);
Slider1.attach(slider1_callback);
Blinker.begin(auth,ssid,pswd);
}
void loop()//不断循环上面的程序
{
Blinker.run();
if(b4==1&&b2==2&&b8==2)//左转
{
analogWrite(5,pwm2);
digitalWrite(16, LOW);
analogWrite(4,pwm2);
digitalWrite(2, LOW);
Serial.print("b4==1&&b2==1 ");
}
else if(b6==1&&b2==2&&b8==2)//右转
{
analogWrite(16,pwm2);
digitalWrite(5, LOW);
analogWrite(2,pwm2);
digitalWrite(4, LOW);
Serial.print("b6==1&&b8==1 ");
}
else if(b8==1) //后退情况
{
analogWrite(5,pwm1);
digitalWrite(16, LOW);
analogWrite(2,pwm1);
digitalWrite(4, LOW);
Serial.print("b8==1");
}
代码只是大致代码,并不全,大家简单看一下就行 非点灯问题,你程序逻辑问题。
一个按键同一时间,只能是一种状态,可以同时按住两个,实现特定功能。
另外还有摇杆模块可用
您好,我知道可以使用遥感模式,只是突然有这个想法,就想实现它,因为我设置,2前进,46转弯,8后退。您看一下。我在串口模式下,按住前进,串口中显示b2=1,然后松手,再然后我单独按d,此时显示b6=1,并且b2b8等于2,但是如果按住前进后再按右,则还是前进状态b2=1
#define BLINKER_PRINT Serial
#define BLINKER_WIFI
//#define BLINKER_ESP_SMARTCONFIG//
#include <Blinker.h>
char auth[] = "0c60094061f8";//填写你点灯科技的密钥
char ssid[] = "MERCURY_79C448";//你WIFI的名称
char pswd[] = "123456789";//你WIFI的密码
int b2;
int b8;
int b4;
int b6;
//按键的代号
BlinkerButton Button2("w");
BlinkerButton Button4("a");
BlinkerButton Button5("b5");
BlinkerButton Button6("d");
BlinkerButton Button8("s");
BlinkerSlider Slider0("s1");
BlinkerSlider Slider1("s2");
int pwm1=60;//q前进速度
int pwm2=60;//转向速度
int flag;//判断当前状态
//16和5在左侧,4和2在右侧
//16前进,4前进
//5后退,2后退
void button2_callback(const String &state)//前进,按下有效的改进
{
if (state == "press")//按下
{
b2=1;
}
else if (state == "pressup")//松开
{
b2=2;
}
}
void button4_callback(const String &state)//左转,按下有效的改进
{
if (state == "press")//按下
{
b4=1;
}
else if (state =="pressup")//松开
{
b4=2;
}
}
void button5_callback(const String &state)//停止
{
BLINKER_LOG("get button state: ", state);
if (state=="press")
{
digitalWrite(16, HIGH);
digitalWrite(5, HIGH);
digitalWrite(4, HIGH);
digitalWrite(2, HIGH);
}
}
void button6_callback(const String &state)//右转,按下有效的改进
{
if (state =="press")//按下
{
b6=1;
}
else if (state == "pressup")//松开
{
b6=2;
}
}
void button8_callback(const String &state)//后退,按下有效的改进
{
if (state == "press")//按下
{
b8=1;
}
else if (state == "pressup")//松开
{
b8=2;
}
}
void slider0_callback(int32_t value) //以下为PWM1方向调参
{
BLINKER_LOG("slider:", value);
pwm1=value;
}
void slider1_callback(int32_t value)//以下为PWM2方向调参
{
BLINKER_LOG("slider:", value);
pwm2=value;
}
//blinker初始化
void blinker_car_init()
{
//1-4号引脚设置为输出模式
pinMode(16, OUTPUT);//
pinMode(5, OUTPUT);//
pinMode(4, OUTPUT);//
pinMode(2, OUTPUT);//
}
void setup()//初始化
{
digitalWrite(D0, HIGH);
digitalWrite(D1, HIGH);
digitalWrite(D2, HIGH);
digitalWrite(D4, HIGH);
analogWriteRange(100);
analogWriteFreq(50);
//analogWrite(D2, 50);//0-10050
//初始化小车参数
blinker_car_init();
Serial.begin(9600);
Serial.println("Please input serial data.");
//按钮绑定
Button2.attach(button2_callback);
Button4.attach(button4_callback);
Button5.attach(button5_callback);
Button6.attach(button6_callback);
Button8.attach(button8_callback);
Slider0.attach(slider0_callback);
Slider1.attach(slider1_callback);
Blinker.begin(auth,ssid,pswd);
}
void loop()//不断循环上面的程序
{
Blinker.run();
if(b4==1&&b2==2&&b8==2)//左转
{
analogWrite(5,pwm2);
digitalWrite(16, LOW);
analogWrite(4,pwm2);
digitalWrite(2, LOW);
Serial.print("b4==1&&b2==2&&b8==2 ");
}
else if(b6==1&&b2==2&&b8==2)//右转
{
analogWrite(16,pwm2);
digitalWrite(5, LOW);
analogWrite(2,pwm2);
digitalWrite(4, LOW);
Serial.print("b6==1&&b2==2&&b8==2");
}
else if(b8==1) //后退情况
{
analogWrite(5,pwm1);
digitalWrite(16, LOW);
analogWrite(2,pwm1);
digitalWrite(4, LOW);
Serial.print("b8==1");
}
//左转
else if(b4==1&&b8==1)
{
analogWrite(5,pwm1);
digitalWrite(16, LOW);
analogWrite(2,pwm1+pwm2);
digitalWrite(4, LOW);
Serial.print("b4==1&&b8==1");
}
//右转
else if(b6==1&&b8==1)
{
analogWrite(5,pwm1+pwm2);
digitalWrite(16, LOW);
analogWrite(2,pwm1);
digitalWrite(4, LOW);
Serial.print("b6==1&&b8==1 ");
}
//松手
else if(b2==1) //前进情况
{
analogWrite(16,pwm1);
digitalWrite(5, LOW);
analogWrite(4,pwm1);
digitalWrite(2, LOW);
Serial.print("b2==1 ");
}
//左转
else if(b4==1&&b2==1)
{
analogWrite(16,pwm1);
digitalWrite(5, LOW);
analogWrite(4,pwm1+pwm2);
digitalWrite(2, LOW);
Serial.print("b4==1&&b2==1 ");
}
//右转
else if(b6==1&&b2==1)
{
analogWrite(16,pwm1+pwm2);
digitalWrite(5, LOW);
analogWrite(4,pwm1);
digitalWrite(2, LOW);
Serial.print("b6==1&&b2==1 ");
}
//松手
else {
digitalWrite(16,LOW);
digitalWrite(5, LOW);
digitalWrite(4,LOW);
digitalWrite(2,LOW);
}
} 奈何col 发表于 2022-5-19 18:41
非点灯问题,你程序逻辑问题。
一个按键同一时间,只能是一种状态,可以同时按住两个,实现特定功能。
另外 ...
新手入门,代码有问题希望斧正,在此先行谢过
页:
[1]