Difference between revisions of "Bluetooth Light"
(Created page with "{{Language| Bluetooth Light}} {| style="width: 800px;" |- | ==Overview== Here we can control the color and brightness of a light by App Android. When the phone is not connecte...") |
(→APP Debugging) |
||
Line 108: | Line 108: | ||
*Setup 1:Scan the two-dimensional code on the left and download Bluetooth Light App. | *Setup 1:Scan the two-dimensional code on the left and download Bluetooth Light App. | ||
[[File:app_Ble_steup1.jpg|600px|center]] | [[File:app_Ble_steup1.jpg|600px|center]] | ||
+ | ios Source download link:[https://github.com/zidong0822/MLight2 LightBlue App] | ||
*Setup 2:Open the App after the download and installation. If the Bluetooth is disconnected, the system will pop up a notice. | *Setup 2:Open the App after the download and installation. If the Bluetooth is disconnected, the system will pop up a notice. | ||
[[File:app_Ble_steup2.jpg|600px|center]] | [[File:app_Ble_steup2.jpg|600px|center]] |
Revision as of 09:24, 17 December 2015
Language: | English • 中文 |
---|
ContentsOverviewHere we can control the color and brightness of a light by App Android. When the phone is not connected to the Bluetooth, the light can automatically change color. While after the phone is connected, you can change the light to any color through the phone. PrincipleThe system can tell whether the mobile phone Bluetooth and mCookie-BT are connected or not. When connected, the system receives the data from the App to the mobile phone mCookie-BT, and analysis it out so as to control the color of the lamp. When the Bluetooth is disconnected, the system enters the pre-set color changing mode. Unless there is a Bluetooth connection, otherwise it'll enter the cycle mode.
Equipment
Preparation
Click Files > Examples > mCookie > _103_BLE_Light, and load the program. Or download:
Program Description
#define my_Serial Serial1
my_Serial.begin(9600);
#define PIXEL_PIN A0 // Digital IO pin connected to the NeoPixels.
#define PIXEL_COUNT 6
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel strip = Adafruit_NeoPixel(6, A0, NEO_GRB + NEO_KHZ800);
sscanf((char *)strstr((char *)buffer, "C:"), "C:%d,%d,%d,%d", &sta[0], &sta[1], &sta[2], &sta[3]); Transmission protocol analyzed from the code: " C:%d,%d,%d,%d " and assign value of the four analyzed data "%d " to sta[0], sta[1], sta[2] and sta[3], three of which are the color values of the R, G and B. The last value is the control mode selection.
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 the value of sta[3] is -1, then all lights connected display the same color. That color is combined by " sta[0], sta[1], sta[2]",namely, the color selected on the phone. Otherwise, these six lights can also be controlled separately.
if (c == '\n')
{
color_en = true;
safe_ms = millis();
}
if (millis() - safe_ms > 3000)//Users can change the time. The unit of "3,000" is "ms".
{
safe_ms = millis();
color_en = false;
}
Hardware Buildup
The connection method of the LED light can refer to the picture below. Please be noted of the connection order, which connect from LED's IN interface to OUT.
APP Debugging
ios Source download link:LightBlue App
Video |