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这个区间

相关推荐
会周易的程序员2 小时前
Libnodave S7 通信库:架构设计与实现解析
linux·c++·物联网·架构·c·s7·工业协议
K成长日志2 小时前
BLE链路层空口包--LE Uncoded PHY
物联网·嵌入式·蓝牙·iot·ble·无线·通信
综合资讯5 小时前
半导体上游ETF的配置标尺
人工智能·科技·物联网·半导体·科创
数字新视界21 小时前
工厂环境安全监控解决方案
物联网·动环监控系统·工厂环境监控
国产化创客1 天前
Kindle完整越狱改造:从闲置泡面盖到Linux开发与智能家居终端
linux·运维·物联网·嵌入式·智能家居·智能硬件
yuanjj881 天前
域格移芯平台模块之open二次开发(一):环境搭建
物联网·二次开发·移芯
MetrixAeroCore2 天前
土耳其物联网卡IMEI注册及120天漫游限制最新合规解读2026
物联网
财复视界2 天前
科源制药医药主业筑基,脑机接口与具身智能打开成长空间
大数据·人工智能·物联网
csg11072 天前
CH340T、CH341T、CH343G 三款USB转串口芯片实用效果对比
单片机·嵌入式硬件·物联网·自动化
2401_859506242 天前
大漆工艺的工程化转型:温湿度PID控制、纳米改性技术与批次一致性方案
大数据·人工智能·物联网