c语言 - 我无法连接ATtiny85和EM18(RFID阅读器)



这是Arduino在线编辑器中的代码

#include <SoftwareSerial.h>
char tag1[12]={"123456789123"};
char tag2[12]={"123456789456"};
char  var[12]={"000000000000"};
int ok;
void setup() {
// put your setup code here, to run once:

Serial.begin(9600);
}
boolean comparetag(char aa[14], char bb[14])
{
boolean ff = false;
int fg = 0;
for (int cc = 0 ; cc < 12 ; cc++)
{
if (aa[cc] == bb[cc])
{
fg++;
}
}
if (fg == 12)
{
ff = true;
}
return ff;
}
void check()
{
ok = 0;
// if it is 1 we have a match, zero is a read but no match,
// -1 is no read attempt made
if (comparetag(var, tag1) == true)
{
ok++;
}
if (comparetag(var, tag2) == true)
{
ok++;
}
}
void reading_data()
{   ok=-1;
int k=0;
char val;
Serial.println("entre the rfid id");
while(!Serial.available())
{
// It waits
}

if(Serial.available()>0)
{     
for(int i=0;i<12;i++)
{
val=Serial.read();
Serial.print(val);
var[i]=val;
while(!Serial.available())
{
// It waits
}

}
check();
}
if (ok > 0) // if we had a match
{ Serial.println('n');
Serial.println("Accepted");

ok = -1;
}
else if (ok == 0) // if we didn't have a match
{Serial.println('n');
Serial.println("Rejected");
ok = -1;
}

}
void loop() {
// put your main code here, to run repeatedly:
reading_data();
}
  1. 我在Arduino IDE中使用了ATtiny85库
  2. 我收到一个错误"Serial未在此范围内声明">

您可能应该包括以下行:

#include <Arduino.h>
#include <HardwareSerial.h>

相关内容

  • 没有找到相关文章

最新更新