0

这是我第一次使用 Arduino Due(或任何 Arduino)。所以昨晚我正在使用我的 Arduino Due,它工作正常。但是当我今天使用它时,它不起作用,所以我尝试检查串行监视器的输出,我看到它产生“ÿ ÿ”额外!

这是我的 Arduino 代码:

//enter code here
int lock = 6;          //pin 6 on Arduino
int unlock = 7;
int lock2 = 8;
int unlock2 = 9;
int lock3 = 10;
int unlock3 = 11;
char final[4];         //Characters the Arduino will receive
char correct[4] = {'A','A','A','A'};    //User-Defined Password
char correct2[4] = {'B','B','B','B'};
char correct3[4] = {'C','C','C','C'};
int pass_correct = 0;          //Does Password match, 0=false 1=true


void setup()
{
pinMode(lock, OUTPUT);
pinMode(lock2, OUTPUT);
pinMode(lock3, OUTPUT);
pinMode(unlock, OUTPUT);
pinMode(unlock2, OUTPUT);
pinMode(unlock3, OUTPUT);
Serial.begin(38400);
Serial2.begin(19200);
Serial3.begin(115200);


digitalWrite(lock, HIGH);  //By default, lock is active(locked)
digitalWrite(lock2, HIGH);
digitalWrite(lock3, HIGH);
digitalWrite(unlock, LOW);
digitalWrite(unlock2, LOW);
digitalWrite(unlock3, LOW);
}

void loop()
{
while(Serial.available()) 
{
  Serial.println("Serial 1 Available");
  for(int i=0; i<4; i++)   //While data is available read 4 bytes
  {
   final[i] = Serial.read();  //Read 4 bytes into the array labled "final"
   Serial.println(final[i]);

  }

  for(int i=0; i<4; i++)
  {
   if(final[i]==correct[i]) //Compare each char received to each car in our password in order
   {
    Serial.println("Serial 1 Block");
    pass_correct = 1;   //If we compare two chars and they match, set the pass_correct variable to true(1)

   }
   else if(final[i]==correct2[i])
   {Serial.println("In Block 2");
    pass_correct = 2;  //Second Lock
    break;   //End loop and stop comparing chars
   }else if(final[i]==correct3[i]){
    Serial.println("Wrong block 3");
      pass_correct = 3; 

   }else {
    Serial.println("Wrong Password");
    pass_correct = 0; // if password does not match;
      break; // end of loop stop comparing
   }
  }
}


while(Serial2.available()) 
{
  for(int i=0; i<4; i++)   //While data is available read 4 bytes
  {
   final[i] = Serial2.read();  //Read 4 bytes into the array labled "final"
  }

  for(int i=0; i<4; i++)
  {
   if(final[i]==correct[i]) //Compare each char received to each car in our password in order
   {
    pass_correct = 1;   //If we compare two chars and they match, set the pass_correct variable to true(1)
    break;
   }
   else if(final[i]==correct2[i])
   {
    pass_correct = 2;  //Second Lock
    break;   //End loop and stop comparing chars
   }else if(final[i]==correct3[i]){
      pass_correct = 3; 
      break;
   }else {
    pass_correct = 0; // if password does not match;
   break; // end of loop stop comparing
   }
  }
}


while(Serial3.available()) 
{
  for(int i=0; i<4; i++)   //While data is available read 4 bytes
  {
   final[i] = Serial3.read();  //Read 4 bytes into the array labled "final"
  }

  for(int i=0; i<4; i++)
  {
   if(final[i]==correct[i]) //Compare each char received to each car in our password in order
   {
    pass_correct = 1;   //If we compare two chars and they match, set the pass_correct variable to true(1)
    break;
   }
   else if(final[i]==correct2[i])
   {
    pass_correct = 2;  //Second Lock
    break;   //End loop and stop comparing chars
   }else if(final[i]==correct3[i]){
      pass_correct = 3; 
      break;
   }else {
    pass_correct = 0; // if password does not match;
   break; // end of loop stop comparing
   }
  }
}

if(pass_correct==1)  //If all chars compared match, deactivate(unlock) the lock for 5 seconds
{
  Serial.println("Unlocked");
  digitalWrite(lock, LOW);
  digitalWrite(unlock, HIGH);
  delay(5000);
  Serial.println("Locked");
  pass_correct = 0;


} else if(pass_correct==2)  //If all chars compared match, deactivate(unlock) the lock for 5 seconds
{
 Serial.println("Unlocked");
  digitalWrite(lock2, LOW);
  digitalWrite(unlock2, HIGH);
  delay(5000);
  Serial.println("Locked");
  pass_correct = 0;

} else if(pass_correct==3)  //If all chars compared match, deactivate(unlock) the lock for 5 seconds
{
 Serial.println("Unlocked");
  digitalWrite(lock3, LOW);
  digitalWrite(unlock3, HIGH);
  delay(5000);
  Serial.println("Locked");
  pass_correct = 0;
}
else 
{
digitalWrite(lock, HIGH); //Else if there was not a complete match, keep the lock high(locked)
}

/* FOR TESTING
Serial.print(final[0]);Serial.print(final[1]);Serial.print(final[2]);Serial.print(final[3]);
Serial.print(" | ");
Serial.print(correct[0]);Serial.print(correct[1]);Serial.print(correct[2]);Serial.print(correct[3]);
Serial.print(" ");
Serial.print(pass_correct);
Serial.println("");
*/
delay(500);


}

当我在串行监视器中输入“AAAA”时,我应该看到已解锁,但我看到...

Serial 1 Available
A
A
A
A
Serial 1 Block
Serial 1 Block
Serial 1 Block
Serial 1 Block
Serial 1 Available




ÿ
ÿ
Wrong Password

我的 Arduino 有可能损坏了吗?

有没有可能的方法来解决它?

请尽快提供帮助。

如果我使用此代码:

char final[4];
void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
Serial.println("Serial Ready");
}

void loop() {
  // put your main code here, to run repeatedly:
  while(Serial.available()){
    for(int i = 0; i<4 ; i++){
      final[i] = Serial.read();
      Serial.println(final[i]);
    }
  }

}

我从串行监视器得到这个:

¿
ÿ
ÿ
ÿ
Serial Ready
A
ÿ
ÿ
ÿ
A
ÿ
ÿ
ÿ
A
ÿ
ÿ
ÿ
A
ÿ
ÿ
ÿ


ÿ
ÿ
ÿ


ÿ
ÿ
ÿ

这就是我上传草图时得到的:

Warning: platform.txt from core 'Arduino ARM (32-bits) Boards' contains deprecated recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} {compiler.ar.extra_flags} "{build.path}/{archive_file}" "{object_file}", automatically converted to recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} {compiler.ar.extra_flags} "{archive_file_path}" "{object_file}". Consider upgrading this core.

Sketch uses 10,252 bytes (1%) of program storage space. Maximum is 524,288 bytes.
Atmel SMART device 0x285e0a60 found
Erase flash
done in 0.031 seconds

Write 11420 bytes to flash (45 pages)

[                              ] 0% (0/45 pages)
[==                            ] 8% (4/45 pages)
[=====                         ] 17% (8/45 pages)
[========                      ] 26% (12/45 pages)
[==========                    ] 35% (16/45 pages)
[=============                 ] 44% (20/45 pages)
[================              ] 53% (24/45 pages)
[==================            ] 62% (28/45 pages)
[=====================         ] 71% (32/45 pages)
[========================      ] 80% (36/45 pages)
[==========================    ] 88% (40/45 pages)
[============================= ] 97% (44/45 pages)
[==============================] 100% (45/45 pages)
done in 2.220 seconds

Verify 11420 bytes of flash

[                              ] 0% (0/45 pages)
[==                            ] 8% (4/45 pages)
[=====                         ] 17% (8/45 pages)
[========                      ] 26% (12/45 pages)
[==========                    ] 35% (16/45 pages)
[=============                 ] 44% (20/45 pages)
[================              ] 53% (24/45 pages)
[==================            ] 62% (28/45 pages)
[=====================         ] 71% (32/45 pages)
[========================      ] 80% (36/45 pages)
[==========================    ] 88% (40/45 pages)
[============================= ] 97% (44/45 pages)
[==============================] 100% (45/45 pages)
Verify successful
done in 2.112 seconds
Set boot flash true
CPU reset.
Invalid library found in C:\Users\Haziq Sheikh\Documents\Arduino\libraries\arduino_199375: C:\Users\Haziq Sheikh\Documents\Arduino\libraries\arduino_199375
Invalid library found in C:\Users\Haziq Sheikh\Documents\Arduino\libraries\SparkFun_LSM303C_6_DOF_IMU_Breakout: C:\Users\Haziq Sheikh\Documents\Arduino\libraries\SparkFun_LSM303C_6_DOF_IMU_Breakout
Invalid library found in C:\Users\Haziq Sheikh\Documents\Arduino\libraries\SparkFun_LSM6DS3_Breakout: C:\Users\Haziq Sheikh\Documents\Arduino\libraries\SparkFun_LSM6DS3_Breakout
Invalid library found in C:\Users\Haziq Sheikh\Documents\Arduino\libraries\SparkFun_MiniGen: C:\Users\Haziq Sheikh\Documents\Arduino\libraries\SparkFun_MiniGen
Invalid library found in C:\Users\Haziq Sheikh\Documents\Arduino\libraries\arduino_199375: C:\Users\Haziq Sheikh\Documents\Arduino\libraries\arduino_199375
Invalid library found in C:\Users\Haziq Sheikh\Documents\Arduino\libraries\SparkFun_LSM303C_6_DOF_IMU_Breakout: C:\Users\Haziq Sheikh\Documents\Arduino\libraries\SparkFun_LSM303C_6_DOF_IMU_Breakout
Invalid library found in C:\Users\Haziq Sheikh\Documents\Arduino\libraries\SparkFun_LSM6DS3_Breakout: C:\Users\Haziq Sheikh\Documents\Arduino\libraries\SparkFun_LSM6DS3_Breakout
Invalid library found in C:\Users\Haziq Sheikh\Documents\Arduino\libraries\SparkFun_MiniGen: C:\Users\Haziq Sheikh\Documents\Arduino\libraries\SparkFun_MiniGen

那么有什么帮助吗?

4

0 回答 0