Bluetooth Lamp

来自Microduino Wikipedia
1304410487@qq.com讨论 | 贡献2015年8月12日 (三) 08:57的版本 Purpose
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)
跳转至: 导航搜索
Language English

Purpose

Using a phone and Microduino-BT to control the color of a lamp by communicating with Microduino-CoreUSB.

Principle

Equipment

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

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:'文件:Microduino-LAMP-APP.zip

Hardware Buildup

  • Setup 1:Stack CoreUSB, BT and Sensorhub.
  • Setup 2:Connect the lantern to the A0 pin of Sensorhub.
Microduino-sensorhub rule.JPG

Software Debugging

  • Setup 1:Build IDE, connect CoreUSB to your PC and download program code.

ble_color_led

  • Setup 2:Download Android Client, decompress, install and open it. Make sure that is operated with Bluetooth open.
Microduino BT Serial 1.png
  • Setup 3:Click SCAN on top right, name it Microduino and click connection.
Microduino BT Serial 2.png
  • Setup 4:It appears Serial Present on top right during initializing and then turn to Serial Ready, meaning normal communication.
Microduino BT Serial 3.png
  • 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.
Microduino BT Serial 5.png
  • 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.

#define my_Serial Serial
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;
  }
}
    • Color change of the light.

When there is Bluetooth connection, the color is:

     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]);
    }

Otherwise, it will control color automatically.

  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);
  }

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