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

相关推荐
SL_staff11 小时前
规则联动:给工厂装上‘自动化神经反射弧’——JVS·物联网平台规则引擎实战教程
java·人工智能·物联网
MuMuMu122311 小时前
越华环保集团碳惠小屋:物联网 + 区块链赋能碳普惠终端,构建可信个人碳账户体系
物联网
注塑机数据采集联网12 小时前
如何解决注塑机数据采集联网对接MES系统数据WiFi传输数据不稳问题
大数据·数据库·物联网·数据挖掘·数据分析
liubinkaixin13 小时前
海上风电叶片试验的上千片应变片,长线干扰怎么解
物联网
数字新视界13 小时前
机房动环监控提升数据中心安全性
物联网·3d·数字孪生·三维可视化·数据可视化
serene9413 小时前
Modbus“出道史”:1979年诞生,后来一路火到现在
物联网·开发·modbus·通讯协议·模拟器
黄鹂鸟科技15 小时前
软件定制开发设计要点:从需求梳理、原型确认到敏捷交付与持续维护
后端·物联网·系统架构
虎王物联15 小时前
随身WiFi什么时候能恢复出厂:去控机和硬刷机的差别
物联网·随身wifi
IT规划师15 小时前
MQTT实战 - QoS 0-1-2 到底怎么选?一张图看懂(四)
物联网·mqtt·.net core·iot·qos