16.风扇

一、功能以及原理

原理:可以逐渐增加风速

二、引脚介绍以及对应开发板可用引脚

旋转按钮引脚:

GND:连接 Arduino 板的 GND

VCC:连接 Arduino 板的 5V

DATA:控制风扇速度,连接 Arduino 数字引脚(0~13)

三、代码控制

  • 设置变量,当变量低于 255 时,逐渐增加
  • 风扇速度根据变量增加而增加
  • 电路连接图可参照相关案例演示

3.1 文本代码

volatile float my_float_variable;

void setup() {
  Serial.begin(9600);

}

void loop() {
    my_float_variable = 0;
    for(  my_float_variable = 0;  my_float_variable <= 255;  my_float_variable++){
      analogWrite(3, my_float_variable);

    }
    delay(0.03 * 1000);

}

3.2 图形化代码

可通过 PWM 信号,控制风扇转速。

四、相关案例演示

1、电路连接图

2、程序运行图

五、相关课程链接

  1. https://www.funcode.cc/course-learn/detail?courseId=68&from=courseList

results matching ""

    No results matching ""