1 前言
由于在mpython中未找到合适的蓝牙监测函数及教程,尝试在mind+上创建模块化的第三方库需要些时间分析main.ts,所以先尝试使用arduino环境检测蓝牙。
2 arduino环境搭建
推荐三篇文章,按照第二篇文章的步骤就可以了。
arduino安装路径
[ESP32]ESP32 Arduino开发环境搭建
ESP32与掌控板IO接口编程入门 | ESP32轻松学(Arduino版)
3 添加库
搜索内容输入Adafruit_NeoPixel
安装好了可以查看到示例
4点亮
#include <Arduino.h>
#include <Adafruit_NeoPixel.h>
Adafruit_NeoPixel pixels(3,17, NEO_GRB + NEO_KHZ800);
void setup() {
Serial.begin(9600);
pixels.begin();
}
void loop() {
Serial.println("set red");
pixels.setPixelColor(0, pixels.Color(0, 150, 0));
pixels.setPixelColor(1, pixels.Color(0, 0, 0));
pixels.show();
Serial.println("success...");
delay(1000);
Serial.println("set green");
//pixels.clear();
pixels.setPixelColor(0, pixels.Color(0, 0, 0));
pixels.setPixelColor(1, pixels.Color(150, 0, 0));
pixels.show();
delay(1000);
Serial.println("success...");
}
初始化
Adafruit_NeoPixel pixels(3,17, NEO_GRB + NEO_KHZ800);
17是参见电路图得到pixel的IO口是IO17
3是三个led,对应0-2
可以查看代码C:\Users\XXX\Documents\Arduino\libraries\Adafruit_NeoPixel\Adafruit_NeoPixel.cpp
/*!
@brief NeoPixel constructor when length, pin and pixel type are known
at compile-time.
@param n Number of NeoPixels in strand.
@param p Arduino pin number which will drive the NeoPixel data in.
@param t Pixel type -- add together NEO_* constants defined in
Adafruit_NeoPixel.h, for example NEO_GRB+NEO_KHZ800 for
NeoPixels expecting an 800 KHz (vs 400 KHz) data stream
with color bytes expressed in green, red, blue order per
pixel.
@return Adafruit_NeoPixel object. Call the begin() function before use.
*/
Adafruit_NeoPixel::Adafruit_NeoPixel(uint16_t n, uint16_t p, neoPixelType t) :
begun(false), brightness(0), pixels(NULL), endTime(0) {
updateType(t);
updateLength(n);
setPin(p);
}
设置颜色
pixels.setPixelColor(1, pixels.Color(150, 0, 0));
显示
pixels.show();