完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
一个非常简单的晶体管电路,带有用于 NodeMCU 的压降。除了这种布局需要一个
RGB 条带外,没有太多要解释的了。单个 可以驱动 5A,这应该留出足够的空间来为平均 5m 的 LED 灯条供电。 按照 btidey 的建议,而是使用 IRLZ44N MOSFET。 确保使用合适的线径和 12V 电源,它可以提供所连接 RGB 条带的总电流消耗。 要添加一些微调,您也可以使用微调电位器代替电阻器。 RGB 控制器 v0.2.jpg :使用排针安装 NodeMCU 并在通过 USB 闪烁时保持它与控制器电路断开连接! 在 NodeMCU 上运行网络服务器,使条带切换到请求的颜色、开/关状态和亮度值。设置后,它会根据 http 请求将当前值返回给 HomeKit。基本上它是Justin Novack 的Homebridge 的 Arduino 类型对应物。下面添加一个与草图匹配的 Homebridge 配置示例 [config.json]。 我在 iOS10(当前为 iOS11)中使用 Apples Home App 设置了条带。一旦将 Homebridge 添加为桥接器,您就可以让 Siri 打开和关闭 RGB 条带,或者将其设置为特定颜色或亮度级别 (0-100%)。 添加了共享的、稳定性改进的用户调整。效果很好,但可以随意进一步改进: 调整:- 按照 J6r06n 的建议与 NodeMCU 的 10 位 pwm 输出匹配 -按照 daniel_asilva 的建议声明引脚模式 - 清除剩余缓冲区以防止 Homebridge 2.0 出现 ECONNRESET,建议由Raptoaaah - 将'x'重新声明为浮点数 - 将'x'重新声明为 int with max() declaration as intended by Willem S -Sketch last revised: 23-Oct-2018 -在此处添加了非阻塞颜色渐变的相同草图 代码:全选//NodeMCU RGB-Controller for Homebridge & HomeKit (Siri) #include #define redPin 13 //D7 - Red channel #define grnPin 12 //D6 - Green channel #define bluPin 14 //D5 - Blue channel #define max(a,b) ((a)>(b)?(a):(b)) //added to make max() work with different data types (int | float) WiFiServer server(80); //Set server port String readString; //String to hold incoming request String hexString = "000000"; //Define inititial color here (hex value), 080100 would be a calm warmtone i.e. int state; int r, g, b, x, V; float R, G, B; ///// WiFi SETTINGS - Replace with your values ///////////////// const char* ssid = "YOUR_ROUTER_SSID"; const char* password = "YOUR_ROUTER_PASSWORD"; IPAddress ip(192, 168, 1, 10); // set a fixed IP for the NodeMCU IPAddress gateway(192, 168, 1, 1); // Your router IP IPAddress subnet(255, 255, 255, 0); // Subnet mask //////////////////////////////////////////////////////////////////// void WiFiStart() { Serial.print("Connecting to "); Serial.println(ssid); WiFi.begin(ssid, password); WiFi.config(ip, gateway, subnet); //Set a fixed IP. You can comment this out and set it in your router instead. while (WiFi.status() != WL_CONNECTED) { delay(100); Serial.print("_"); } Serial.println(); Serial.println("Done"); Serial.print("IP address: "); Serial.println(WiFi.localIP()); Serial.println(""); server.begin(); } void allOff() { state = 0; analogWrite(redPin, 0); analogWrite(grnPin, 0); analogWrite(bluPin, 0); } //Write requested hex-color to the pins (10bit pwm) void setHex() { state = 1; long number = (long) strtol( &hexString[0], NULL, 16); r = number >> 16; g = number >> 8 & 0xFF; b = number & 0xFF; r = map(r, 0, 255, 0, 1023); //added for 10bit pwm g = map(g, 0, 255, 0, 1023); //added for 10bit pwm b = map(b, 0, 255, 0, 1023); //added for 10bit pwm analogWrite(redPin, (r)); analogWrite(grnPin, (g)); analogWrite(bluPin, (b)); } //Compute current brightness value void getV() { R = roundf(r / 10.23); //for 10bit pwm, was (r/2.55); G = roundf(g / 10.23); //for 10bit pwm, was (g/2.55); B = roundf(b / 10.23); //for 10bit pwm, was (b/2.55); x = max(R, G); V = max(x, B); } //For serial debugging only void showValues() { Serial.print("Status on/off: "); Serial.println(state); Serial.print("RGB color: "); Serial.print(r); Serial.print("."); Serial.print(g); Serial.print("."); Serial.println(b); Serial.print("Hex color: "); Serial.println(hexString); getV(); Serial.print("Brightness: "); Serial.println(V); Serial.println(""); } void setup() { Serial.begin(9600); delay(1); pinMode(redPin, OUTPUT); //declaration added pinMode(grnPin, OUTPUT); //declaration added pinMode(bluPin, OUTPUT); //declaration added setHex(); //Set initial color after booting. Value defined above WiFi.mode(WIFI_STA); WiFiStart(); //showValues(); //Uncomment for serial output } void loop() { WiFiClient client = server.available(); if (!client) { return; } while (client.connected() && !client.available()) { delay(1); } //Respond on certain Homebridge HTTP requests if (client) { while (client.connected()) { if (client.available()) { char c = client.read(); if (readString.length() < 100) { readString += c; } if (c == '\n') { //Serial.print("Request: "); //Uncomment for serial output //Serial.println(readString); //Uncomment for serial output //Send reponse: client.println("HTTP/1.1 200 OK"); client.println("Content-Type: text/html"); client.println(); //On: if (readString.indexOf("on") > 0) { setHex(); //showValues(); } //Off: if (readString.indexOf("off") > 0) { allOff(); //showValues(); } //Set color: if (readString.indexOf("set") > 0) { hexString = ""; hexString = (readString.substring(9, 15)); setHex(); //showValues(); } //Status on/off: if (readString.indexOf("status") > 0) { client.println(state); } //Status color (hex): if (readString.indexOf("color") > 0) { client.println(hexString); } //Status brightness (%): if (readString.indexOf("bright") > 0) { getV(); client.println(V); } delay(1); while (client.read() >= 0); //added: clear remaining buffer to prevent ECONNRESET client.stop(); readString.remove(0); } } } } } 代码:全选{ "bridge": { "name": "Homebridge", "username": "CC:22:3D:E3:CE:30", "port": 51826, "pin": "031-45-154" }, "description": "Example configuration file for NodeMCU-RGB-Controller and better-http-rgb plugin", "accessories": [{ "accessory": "HTTP-RGB", "name": "RGB Strip", "switch": { "status": "http://192.168.1.10:80/status", "powerOn": "http://192.168.1.10:80/on", "powerOff": "http://192.168.1.10:80/off" }, "color": { "status": "http://192.168.1.10:80/color", "url": "http://192.168.1.10:80/set/%s" }, "brightness": { "status": "http://192.168.1.10:80/bright", "url": "http://192.168.1.10:80/set/%s" } }], "platforms": [] } |
|
相关推荐
|
|
只有小组成员才能发言,加入小组>>
988 浏览 1 评论
554浏览 6评论
463浏览 5评论
有没有办法在不使用混杂模式的情况下实现Wifi驱动程序接收缓冲区访问中断呢?
447浏览 5评论
448浏览 4评论
422浏览 4评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-29 11:18 , Processed in 0.649936 second(s), Total 43, Slave 36 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号