首先我们用到的材料有 arduino nano、蓝牙模块、da大功率mos管模块、散热风扇、ws2812b灯带\DC-DC电源等材料。
说一下思路,风扇通过大功率mos管控制进风量,手机通过蓝牙控制风扇的转速以及灯带的颜色。
引脚接法:
arduino ----- 蓝牙
11----- TX
12----- RX
GND----- GND
VCC----- VCC
arduino -----ws2812b灯带
4-----DIN
GND-----GND
外接电源+-----VCC
arduino -----大功率mos管模块
GND-----GND
3-----pwm+
DC+和DC-接电源输入
OUT+和OUT-接风扇
(注:风扇和灯带的电源推荐用外接电源,不然电流不稳定会影响arduino正常工作)
手机端设置:
代码如下:
[mw_shl_code=arduino,true]#define BLINKER_PRINT Serial
#define BLINKER_BLE
#include <PWM.h>
#include <Blinker.h>
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
#define PIN 4 //ws2812b灯带引脚
#define NUMPIXELS 16 //灯珠数量
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
#define RGB_1 "RGBKey"
BlinkerSlider Slider1("fan");
BlinkerRGB RGB1(RGB_1);
void slider1_callback(int32_t value1)
{
BLINKER_LOG("get slider value: ", value1);
OCR2B = value1; //Toggle value B, Output at pin 3
}
void rgb1_callback(uint8_t r_value, uint8_t g_value, uint8_t b_value, uint8_t bright_value)
{
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
BLINKER_LOG("R value: ", r_value);
BLINKER_LOG("G value: ", g_value);
BLINKER_LOG("B value: ", b_value);
BLINKER_LOG("Rrightness value: ", bright_value);
uint8_t colorR = map(r_value, 0, 255, 0, bright_value);
uint8_t colorG = map(g_value, 0, 255, 0, bright_value);
uint8_t colorB = map(b_value, 0, 255, 0, bright_value);
for(int i = 0; i < NUMPIXELS; i++)
{
pixels.setPixelColor(i, pixels.Color(colorR,colorG,colorB));
pixels.show();
}
}
void setup()
{
Serial.begin(115200);
#if defined(BLINKER_PRINT)
BLINKER_DEBUG.stream(BLINKER_PRINT);
#endif
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);
Blinker.begin(11, 12);//设置数字IO口11(RX)12(TX)这两个脚接蓝牙TX RX
pixels.begin();
Slider1.attach(slider1_callback);
RGB1.attach(rgb1_callback);
InitTimersSafe();
pinMode(3, OUTPUT); //风扇引脚
TCCR2A = _BV(COM2A0) | _BV(COM2B1) | _BV(WGM21) | _BV(WGM20); //Set Timer2 to varying top limit fast PWM mode
// TCCR2B = _BV(WGM22) | _BV(CS22) | _BV(CS21) | _BV(CS20);//another way to set prescaler CS2=fff
TCCR2B = TCCR2B & 0b11111000 | 0x01;
OCR2A = 255;
OCR2B = 10;
}
void loop()
{
Blinker.run();
// Serial.println(i);
}[/mw_shl_code]
|