我有一个蓝牙屏蔽。 (https://www.hackerstore.nl/PDFs/BTShield.pdf) 已连接电源(5V) 将蓝牙连接到我的Mac osx(蓝牙首选项中显示为HC-05)
在Arduino程序中,端口已连接。我的第一个假设是我的代码应该运行,但是尝试时会出现此错误:
avrdude: ser_open(): can't open device "/dev/cu.HC-05-DevB": Resource busy.
我可能会丢失一些东西吗?到目前为止,我还没有更改任何处理或Arduino代码,对吗?还是这里有其他问题?
这是Arduino代码:
#include <FastLED.h>
#define LED_PIN 13
#define NUM_LEDS 36
CRGB leds[NUM_LEDS];
void setup()
{
FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS);
Serial.begin(9600);
FastLED.clear();
FastLED.show();
}
void loop()
{
if (Serial.available() > 0)
{
int incomingByte = Serial.read();
if (incomingByte > '0' && incomingByte < '7')
{
FastLED.clear(); // <-----<<<< USE clear
}
if (incomingByte == '1')
{
leds[0] = CRGB(255, 0, 0);
leds[6] = CRGB(255, 0, 0);
leds[12] = CRGB(255, 0, 0);
leds[18] = CRGB(255, 0, 0);
leds[24] = CRGB(255, 0, 0);
leds[30] = CRGB(255, 0, 0);
}
else if (incomingByte == '2')
{
leds[1] = CRGB(255, 0, 0);
leds[7] = CRGB(255, 0, 0);
leds[13] = CRGB(255, 0, 0);
leds[19] = CRGB(255, 0, 0);
leds[25] = CRGB(255, 0, 0);
leds[31] = CRGB(255, 0, 0);
}
else if (incomingByte == '3')
{
leds[2] = CRGB(255, 0, 0);
leds[8] = CRGB(255, 0, 0);
leds[14] = CRGB(255, 0, 0);
leds[20] = CRGB(255, 0, 0);
leds[26] = CRGB(255, 0, 0);
leds[32] = CRGB(255, 0, 0);
}
else if (incomingByte == '4')
{
leds[3] = CRGB(255, 0, 0);
leds[9] = CRGB(255, 0, 0);
leds[15] = CRGB(255, 0, 0);
leds[21] = CRGB(255, 0, 0);
leds[27] = CRGB(255, 0, 0);
leds[33] = CRGB(255, 0, 0);
}
else if (incomingByte == '5')
{
leds[4] = CRGB(255, 0, 0);
leds[10] = CRGB(255, 0, 0);
leds[16] = CRGB(255, 0, 0);
leds[22] = CRGB(255, 0, 0);
leds[28] = CRGB(255, 0, 0);
leds[34] = CRGB(255, 0, 0);
}
else if (incomingByte == '6')
{
leds[5] = CRGB(255, 0, 0);
leds[11] = CRGB(255, 0, 0);
leds[17] = CRGB(255, 0, 0);
leds[23] = CRGB(255, 0, 0);
leds[29] = CRGB(255, 0, 0);
leds[35] = CRGB(255, 0, 0);
}
FastLED.show();
}
}
谢谢您的帮助!
更新:
好,所以我发现运行处理草图会影响蓝牙模块。 HC-05较早断开连接时出现了一些问题,但保持处理草图运行仍可保持蓝牙连接。
以下是处理代码:
float x = 100;
float y = 50;
float w = 150;
float h = 80;
import org.openkinect.freenect.*;
import org.openkinect.processing.*;
import processing.serial.*;
// The kinect stuff is happening in another class
KinectTracker tracker;
Kinect kinect;
Serial myPort;
void setup() {
size(512, 424);
kinect = new Kinect(this);
tracker = new KinectTracker();
String portName = Serial.list()[3]; //change the 0 to a 1 or 2 etc. to match your port
myPort = new Serial(this, portName, 9600);
}
void draw() {
tracker.track();
tracker.display();
PVector v1 = tracker.getPos();
fill(50, 100, 250, 200);
noStroke();
ellipse(v1.x, v1.y, 50, 50);
//1
if (v1.x > 0 && v1.x < 50 ){
println('1');
//rect(0,200,200,200);
myPort.write('1'); }
//println('0'); }
//2
if (v1.x > 50 && v1.x < 100){
println('2');
myPort.write('2'); }
//3
if (v1.x > 100 && v1.x < 150 ){
println('3');
myPort.write('3'); }
//4
if (v1.x > 150 && v1.x < 200 ){
println('4');
myPort.write('4'); }
//5
if (v1.x > 200 && v1.x < 250 ){
println('5');
myPort.write('5'); }
//6
if (v1.x > 250 && v1.x < 300 ){
println('6');
myPort.write('6'); }
}
因此,现在我想让arduino可能会因为HC05从处理中接收信号而感到忙碌吗?我在想BAUD汇率可能与此有关吗?