查看“Bluetooth Lamp”的源代码
←
Bluetooth Lamp
跳转至:
导航
、
搜索
因为以下原因,您没有权限编辑本页:
您所请求的操作仅限于该用户组的用户使用:
用户
您可以查看与复制此页面的源代码。
{{Language| Bluetooth Lamp}} {| style="width: 800px;" |- | ==Purpose== Using a phone and Microduino-BT to control the color of a lamp by communicating with Microduino-CoreUSB. ==Principle== ==Equipment== {|class="wikitable" |- |Module||Number||Function |- |[[Microduino-CoreUSB]]||1||Core board |- |[[Microduino-Sensorhub]]||1||Sensor pinboard |- |[[Microduino-BT]]||1||Bluetooth module |- | [[Microduino-Lantern]]||1||colored light |- | [[Microduino-BM]]||1||Battery management |} [[File:ble_lamp.jpg|600px|center|thumb]] ==Document== Android Client: Caution: The new BT 4.0 version can only be supported by Android 4.3 and higher. Here we offer Android App. APP download:'''[[File:Microduino-LAMP-APP.zip]]'' ==Hardware Buildup== *Setup 1:Stack CoreUSB, BT and Sensorhub. [[File:CoreUSB_Ble_Sensorhub.jpg|600px|center|thumb]] *Setup 2:Connect the lantern to the A0 pin of Sensorhub. [[file:Microduino-sensorhub_rule.JPG|thumb|800px|center]] [[File:mic_colorled_ble.jpg|600px|center|thumb]] ==Software Debugging== *Setup 1:Build IDE, connect CoreUSB to your PC and download program code. [https://github.com/Microduino/Microduino_Tutorials/blob/master/MCookie_Tutorial/ble_color_led/ble_color_led.ino ble_color_led] *Setup 2:Download Android Client, decompress, install and open it. Make sure that is operated with Bluetooth open. [[File:Microduino_BT_Serial_1.png||300px|center|thumb]] *Setup 3:Click SCAN on top right, name it Microduino and click connection. [[File:Microduino_BT_Serial_2.png||300px|center|thumb]] *Setup 4:It appears Serial Present on top right during initializing and then turn to Serial Ready, meaning normal communication. [[File:Microduino_BT_Serial_3.png||300px|center|thumb]] *APP description: **If you have multiple colored lights, you can switch to Multi Colore mode. The maximum is six. **Control the brightness through the circular ring. **Switch to turn on or off through the bottom button. [[File:Microduino_BT_Serial_5.png||300px|center|thumb]] *Code description: One part for receiving Bluetooth information and the other for controlling color combination of the light via analog value. **Reading Bluetooth information The use of BT serial port is baseed on the selection of serial jumper on the board. The default serial port is 0:Serial. <source lang="cpp"> #define my_Serial Serial </source> <source lang="cpp"> void ble() { while (my_Serial.available()) { char c = my_Serial.read(); delay(2); if (c == 'C') buffer_sta = true; if (c == '\n') { color_en = true; safe_ms = millis(); } if (buffer_sta) { buffer[buffer_num] = c; buffer_num++; } // Serial.println(c); //Serial.println(color_en); } if (buffer_sta) { buffer_sta = false; sscanf((char *)strstr((char *)buffer, "C:"), "C:%d,%d,%d,%d", &sta[0], &sta[1], &sta[2], &sta[3]); for (int a = 0; a < buffer_num; a++) buffer[a] = NULL; buffer_num = 0; for (int i = 0; i < 4; i++) { Serial.print(sta[i]); Serial.print(","); } Serial.println(" "); if (-1 == sta[3]) { colorSet(strip.Color(sta[0], sta[1], sta[2])); } else if ((0 <= sta[3]) && (sta[3] < PIXEL_COUNT)) { colorSet(strip.Color(sta[0], sta[1], sta[2]), sta[3]); } } if (millis() - safe_ms > 3000) { safe_ms = millis(); color_en = false; } } </source> **Color change of the light. When there is Bluetooth connection, the color is: <source lang="cpp"> if (-1 == sta[3]) { colorSet(strip.Color(sta[0], sta[1], sta[2])); } else if ((0 <= sta[3]) && (sta[3] < PIXEL_COUNT)) { colorSet(strip.Color(sta[0], sta[1], sta[2]), sta[3]); } </source> Otherwise, it will control color automatically. <source lang="cpp"> if (!color_en) { rainbowCycle(10, 255, 0, 0, 0); rainbowCycle(10, 255, 0, 0, 1); rainbowCycle(10, 0, 255, 0, 0); rainbowCycle(10, 0, 255, 0, 1); rainbowCycle(10, 0, 0, 255, 0); rainbowCycle(10, 0, 0, 255, 1); rainbowCycle(10, 255, 0, 225, 0); rainbowCycle(10, 255, 0, 225, 1); rainbowCycle(10, 247, 139, 5, 0); rainbowCycle(10, 247, 139, 5, 1); rainbowCycle(10, 255, 255, 0, 0); rainbowCycle(10, 255, 255, 0, 1); rainbowCycle(10, 0, 255, 255, 0); rainbowCycle(10, 0, 255, 255, 1); for (int i = 0; i < 3; i++) rainbow(30); } </source> ==Result== By Microduino, you can control colored lights through your phone and get any color you want. (You can build a beautiful frame with LEGO. ) ==Video== |}
该页面使用的模板:
模板:Language
(
查看源代码
)
模板:Nmbox
(
查看源代码
)
返回至
Bluetooth Lamp
。
导航菜单
个人工具
创建账户
登录
名字空间
页面
讨论
变种
视图
阅读
查看源代码
查看历史
更多
搜索
Welcome
首页
创客大赛
大赛详情
3D打印
安装月球车
图形化编程
操控月球车
升级月球车
编程工具下载
软件下载
Arduino
Processing
Mixly
Scratch
模块套件
Microduino 102
mCookie 102
mCookie 202
mCookie 302
IBC
其他
应用套件
四轴飞行器
平衡车
小车CUBE
音乐播放器
刷卡音乐播放器
wifi气象站
彩虹音乐触摸灯
分贝检测仪
迎门汇报
LED点阵时钟
LED点阵屏幕
硬件
mCookie
Sensor
Microduino
MicroWrt
MicroNux
MicroRobot-Core
MicroRobot-CoreESP
ideaBoard
ideaBox
MicroMV
MicroAI
帮助
常见问题
帮助
工具
链入页面
相关更改
特殊页面
页面信息