KFC玩具HelloKitty风扇改造——ESP32蓝牙blinker、1404无刷电机、双18650

改装KFC玩具------ESP32蓝牙无刷风扇

ESP32代码:

使用NodeMCU-32S

cpp 复制代码
#define BLINKER_BLE

#include <Blinker.h>

#include <Arduino.h>

 // PWM通道
int channel_PWM = 3;  
// PWM频率,那么周期也就是1/50,也就是20ms ,PWM一共有16个通道,0-7位高速通道由80Mhz时钟驱动,后面8个为低速通道由1Mhz时钟驱动
int freq_PWM = 50;   
// PWM分辨率,取值为 0-20 之间  ,这里填写为10,那么后面的ledcWrite 这个里面填写的pwm值就在 0 - 2的10次方 之间 也就是 0-1024 ,如果是要求不高的东西你可以直接拿1000去算了
int resolution_PWM = 10;   
// 绑定的IO,在下面的绑定函数里面会用到,绑定之后这个IO就会变成我们PWM的输出口
const int PWM_Pin = 4;  //指定pwm绑定到这个io上输出

BlinkerButton Button1("btn-abc");
BlinkerButton Button2("btn-1");
BlinkerSlider Slider0("Pwm");
BlinkerNumber Number1("num-abc");

int counter = 0;

void button1_callback(const String & state)
{
    BLINKER_LOG("get button state: ", state);
    digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
}

void button2_callback(const String & state)
{
    BLINKER_LOG("get button state: ", state);
    digitalWrite(0, !digitalRead(0));
}

void slider0_callback(int32_t value) //滑块0
{
    int servo = 1000 - value;
    ledcWrite(channel_PWM, servo);
}

void dataRead(const String & data)
{
    BLINKER_LOG("Blinker readString: ", data);
    counter++;
    Number1.print(counter);
}

void setup()
{
    Serial.begin(115200);
    BLINKER_DEBUG.stream(Serial);

    ledcSetup(channel_PWM, freq_PWM, resolution_PWM); // 设置舵机通道
    ledcAttachPin(PWM_Pin, channel_PWM);  //将 LEDC 通道绑定到指定 IO 口上以实现输出
    
    pinMode(LED_BUILTIN, OUTPUT);
    digitalWrite(LED_BUILTIN, HIGH);

    pinMode(0, OUTPUT);
    digitalWrite(0, HIGH);
    
    Blinker.begin();
    Blinker.attachData(dataRead);

    Button1.attach(button1_callback);
    Button2.attach(button2_callback);
    Slider0.attach(slider0_callback);
}

void loop()
{
    Blinker.run();
}

Blinker界面:

PWM调速为0~1024,取550到650这个区间

相关推荐
数字新视界3 小时前
动环监控信创适配助力机房管理智能化转型
物联网·数据中心·动环监控·微模块机房·模块化机房
乐橙开放平台8 小时前
物业 SaaS 笔记:子账号 Policy 按通道隔离,At_ 管控面 / St_ 数据面治理 accessToken
后端·物联网·音视频
DoLovya8 小时前
从零实现 ESP8266 + MQTT 智能门禁:公网一键开门、舵机控制、在线监控完整方案
python·物联网·mqtt·嵌入式·esp8266·门禁系统
悟天特斯9 小时前
智慧楼宇自控系统重构:从传统BA到AI自适应控制的架构演进
人工智能·物联网·重构·架构
绿智校园12 小时前
一套基座替代五类系统:DeepBasic Folar与传统BA/SCADA/IoT平台的架构对比
物联网·架构
钒星物联网12 小时前
自组网+Ku宽带卫星图传,为野保监测搭建空天地一体化高速通道
数码相机·物联网·卫星通信·红外相机·自组网·野外监测
MuMuMu122313 小时前
末端低碳物联网终端数据设计:越华环保集团碳惠小屋数据合规与适配方案
物联网
longxingiot14 小时前
智慧园区全域管控物联网主机应用
网络·物联网
研华科技Advantech14 小时前
Windows Server IoT 2025深度技术解析:功能、安全与AI性能突破
人工智能·物联网·安全
会周易的程序员1 天前
aiDgePLC iec61131 虚拟机 完整使用文档
c++·物联网·架构·st·iec61131