用于字符数组的初始化字符串在Arduino上的错误太长

时间:2013-10-03 17:54:52

标签: arduino chars bluesmirf

我正在尝试在Arduino上运行下面的代码但是当我验证代码时,它显示, '字符数组的初始化字符串太长'。 虽然我已经阅读过类似问题的先前问题,但我不知道从现在尝试的代码中开始的位置。是的,我对C ++世界很新,如果你能给我一个自学或直接答案的线索,那将是非常感激的。

最佳,

/**** SET YOUR MAC ADDRESS HERE ****/

char mac[13] = "74-E5-43-BE-42-10";

/***********************************/


#define LED 13
#define BLUESMIRFON 2

#define FACTORYRESETBAUD 57600
#define DEFAULTBAUD 115200

char str[3];
char passkey[5] = "0000";

boolean success = false;

int failOuts[10] = {3,4,5,6,7,8,9,10,11,12};

void setup() 
{ 
//Initialize pins
pinMode(LED, OUTPUT);
pinMode(BLUESMIRFON, OUTPUT);
for (int i=0; i<10; i++) {
pinMode(failOuts[i], OUTPUT);
}

// First reset to factory defaults
while (!success) {
RunBlueSmirfSetup(true);
}
success = false;
// Then set up with the correct mac address
RunBlueSmirfSetup(false);
} 

void loop() {   
if(success) {
digitalWrite(LED,LOW);
delay(1000);
digitalWrite(LED,HIGH);
delay(1000);
}    
} 

void RunBlueSmirfSetup(boolean factoryReset) {

//Initialize serial ports
if (factoryReset) {
Serial.begin(FACTORYRESETBAUD);   
} else {
Serial.begin(DEFAULTBAUD);   
}   

digitalWrite(BLUESMIRFON, LOW);
delay(2000);
digitalWrite(BLUESMIRFON, HIGH);  
delay(2000);              //Wait for BlueSMIRF to turn on

Serial.print('$');      //Send command to put BlueSMIRF into programming mode
Serial.print('$');
Serial.print('$');

delay(100);
Serial.flush();

//Reset the module
if (factoryReset) {
Serial.print('S');
Serial.print('F');
Serial.print(',');
Serial.print('1');
Serial.print('\r');  

while(Serial.available() < 3);
str[0] = (char)Serial.read();
str[1] = (char)Serial.read();
str[2] = (char)Serial.read();  
if(str[0] == 'A' && str[1] == 'O' && str[2] == 'K') {
  success = true;
} else {
  success = false;
  digitalWrite(failOuts[0],HIGH);
}
delay(100);
Serial.flush();
} else {
//Set the baudrate
Serial.print('S');
Serial.print('U');
Serial.print(',');
Serial.print('5');
Serial.print('7');
Serial.print('\r');  

while(Serial.available() < 3);
str[0] = (char)Serial.read();
str[1] = (char)Serial.read();
str[2] = (char)Serial.read();  
if(str[0] == 'A' && str[1] == 'O' && str[2] == 'K') {
  success = true;
} else {
  success = false;
  digitalWrite(failOuts[1],HIGH);
}
delay(100);
Serial.flush();

//Set the remote MAC address
Serial.print('S');
Serial.print('R');
Serial.print(',');
for(int i = 0; i < 12; i++) {
  Serial.print(mac[i]);
}
Serial.print('\r');  

while(Serial.available() < 3);
str[0] = (char)Serial.read();
str[1] = (char)Serial.read();
str[2] = (char)Serial.read();  
if(str[0] == 'A' && str[1] == 'O' && str[2] == 'K') {
  success = true;
} else {
  success = false;
  digitalWrite(failOuts[2],HIGH);
}
delay(100);
Serial.flush();

//Set the passkey
Serial.print('S');
Serial.print('P');
Serial.print(',');
for(int i = 0; i < 4; i++) {
  Serial.print(passkey[i]);
}
Serial.print('\r');  

while(Serial.available() < 3);
str[0] = (char)Serial.read();
str[1] = (char)Serial.read();
str[2] = (char)Serial.read();  
if(str[0] == 'A' && str[1] == 'O' && str[2] == 'K') {
  success = true;
} else {
  success = false;
  digitalWrite(failOuts[3],HIGH);
}
delay(100);
Serial.flush(); 

//Set the BlueSMiRF mode
Serial.print('S');
Serial.print('M');
Serial.print(',');
Serial.print('3');
Serial.print('\r');

while(Serial.available() < 3);
str[0] = (char)Serial.read();
str[1] = (char)Serial.read();
str[2] = (char)Serial.read();  
if(str[0] == 'A' && str[1] == 'O' && str[2] == 'K') {
  success = true;
} else {
  success = false;
  digitalWrite(failOuts[4],HIGH);
}
delay(100);
Serial.flush();

delay(100);
//Exit command mode
} 
Serial.print('-');
Serial.print('-');
Serial.print('-');
Serial.print('\r');

//delay(100);
//Serial.flush();
//delay(100);
//Serial.end();
//digitalWrite(BLUESMIRFON, LOW);
}
CleanProgramBlueSMiRF CleanProgramBlueSMiRF 

1 个答案:

答案 0 :(得分:0)

如果您复制了包含行号的确切错误消息,将会有所帮助。

我认为它失败了:

char mac[13] = "74-E5-43-BE-42-10";

因为它在引号之间有17个字符,你分配了13个。