Arduino问题

Arduino problems

提问人:koray.gnsl 提问时间:1/24/2022 最后编辑:gre_gorkoray.gnsl 更新时间:1/25/2022 访问量:109

问:

我有一个问题。我正在使用 Arduino,但我不擅长 C++,并且我犯了错误。我在主动安全系统上工作。我曾经使用过运动传感器、RFID、嵌入式时钟和 wifi 模型。但是我说,我犯了一个错误,你能帮我吗?

#include <SoftwareSerial.h>
#include <MFRC522.h>
#include <SPI.h>
#include <virtuabotixRTC.h>

String agAdi = "";
String agSifresi = "";

int rxPin = 3;
int txPin = 5;
int RST_PIN = 9;
int SS_PIN = 10;
int CLK_PIN = 6;
int DAT_PIN = 7;
int PST_PIN = 4;
int buzzerPin = 2;
int pirPin = 8;
int hareket;
int tarih;
int saat;

String ip = "";
MFRC522 rfid(SS_PIN, RST_PIN);
byte ID[4] = {47, 219, 106, 81};
byte okunandeger[4];

virtuabotixRTC myRTC(CLK_PIN, DAT_PIN, RST_PIN);

SoftwareSerial esp(rxPin, txPin);

void setup() {
  pinMode(pirPin, INPUT);
  pinMode(buzzerPin, OUTPUT);

  myRTC.setDS1302Time(00, 57, 22, 7, 23, 1, 2022);

  Serial.begin(9600);
  SPI.begin();
  rfid.PCD_Init();

  Serial.println("Started");
  esp.begin(115200);
  esp.println("AT");
  Serial.println("AT Yollandı");
  while (!esp.find("OK")) {
    esp.println("AT");
    Serial.println("ESP8266 Bulunamadı.");
  }
  Serial.println("OK Komutu Alındı");
  esp.println("AT+CWMODE=1");
  while (!esp.find("OK")) {
    esp.println("AT+CWMODE=1");
    Serial.println("Ayar Yapılıyor....");
  }
  Serial.println("Client olarak ayarlandı");
  Serial.println("Aga Baglaniliyor...");
  esp.println("AT+CWJAP=\"" + agAdi + "\",\"" + agSifresi + "\"");
  while (!esp.find("OK"))
    ;
  Serial.println("Aga Baglandi.");
  delay(1000);
}
void loop() {
  saatModulu();
  rfidGiris();

  byte okunankart[4] = rfid.uid.uidByte[];
  int saat = String(myRTC.hours + ":" + myRTC.minutes + ":" + myRTC.seconds);
  int tarih = String(myRTC.dayofmonth + ":" + myRTC.month + ":" + myRTC.year);

  espFonk();
  rfidCikis();

  okunankart = rfid.uid.uidByte[];
  int saat = String(myRTC.hours + ":" + myRTC.minutes + ":" + myRTC.seconds);
  int tarih = String(myRTC.dayofmonth + ":" + myRTC.month + ":" + myRTC.year);

  espFonk();
}

void espFonk() {
  esp.println("AT+CIPSTART=\"TCP\",\"" + ip + "\",80");
  if (esp.find("Error")) {
    Serial.println("AT+CIPSTART Error");
  }
  String veri = "GET https://api.thingspeak.com/update?api_key=";
  veri += "&field1=";
  veri += String(okunankart);
  veri += "&field2=";
  veri += String(saat);
  veri += "&field3=";
  veri += String(tarih);
  veri += "\r\n\r\n";
  esp.print("AT+CIPSEND=");
  esp.println(veri.length() + 2);
  delay(2000);
  if (esp.find(">")) {
    esp.print(veri);
    Serial.println(veri);
    Serial.println("Veri gonderildi.");
    delay(1000);
  }
  Serial.println("Baglantı Kapatildi.");
  esp.println("AT+CIPCLOSE");
  delay(1000);
}

void rfidGiris() {
  if (!rfid.PICC_IsNewCardPresent()) return;
  if (!rfid.PICC_ReadCardSerial()) return;

  if (rfid.uid.uidByte[0] == ID[0] && rfid.uid.uidByte[1] == ID[1] &&
      rfid.uid.uidByte[2] == ID[2] && rfid.uid.uidByte[3] == ID[3]) {
    Serial.println("Güvenlik Sistemi Aktif!");
    ekranaYazdir();
    hareketSensor();
  }

  else {
    Serial.print("Yetkisiz Kart");
    ekranaYazdir();
    melodi(500);
    delay(500);
    melodi(500);
  }

  rfid.PICC_HaltA();
}

void ekranaYazdir() {
  Serial.print("ID Numarası : ");
  for (int sayac = 0; sayac < 4; sayac++) {
    Serial.print(rfid.uid.uidByte[sayac]);
    Serial.print(" ");
  }
}

void saatModulu() {
  myRTC.updateTime();

  Serial.print("Tarih / Saat: ");
  Serial.print(myRTC.dayofmonth);
  Serial.print("/");
  Serial.print(myRTC.month);
  Serial.print("/");
  Serial.print(myRTC.year);
  Serial.print(" ");
  Serial.print(myRTC.hours);
  Serial.print(":");
  Serial.print(myRTC.minutes);
  Serial.print(":");
  Serial.print(myRTC.seconds);

  delay(1000);
}

void hareketSensor() {
  hareket = digitalRead(pirPin);

  if (Hareket == HIGH) {
    melodi(5000);
  }
}

int melodi(int dly) {
  tone(buzzerPin, 832);
  delay(dly);
  noTone(buzzerPin);
  delay(dly);
}

void rfidCikis() {
  if (!rfid.PICC_IsNewCardPresent()) return;
  if (!rfid.PICC_ReadCardSerial()) return;

  if (rfid.uid.uidByte[0] == ID[0] && rfid.uid.uidByte[1] == ID[1] &&
      rfid.uid.uidByte[2] == ID[2] && rfid.uid.uidByte[3] == ID[3]) {
    Serial.println("Güvenlik Sistemi Deaktif!");
    ekranaYazdir();
    hareket = LOW;
  }

  else {
    Serial.print("Yetkisiz Kart");
    ekranaYazdir();
    melodi(500);
    delay(500);
    melodi(500);
  }

  rfid.PICC_HaltA();
}

这是错误:main.ino:166:8:注意:建议的替代方案:“hareket” 退出状态 1 ']' 标记前的预期 primary-expression

和 Arduino IDE 照明

okunankart = rfid.uid.uidByte[];
C++ 数组 arduino 赋值运算符 arduino-esp8266

评论

0赞 Heinrich supports Monica 1/24/2022
错误消息告诉您第 166 行有错误。它甚至提出了一个替代方案。你用一个大的“H”写了“Hareket”,而你用一个小的“h”声明了变量。C++区分大小写。
0赞 gre_gor 1/25/2022
不要在某人已经发布答案后更改问题。
0赞 Dúthomhas 1/25/2022
您正在公共论坛上发布活动安全系统的代码?你确定它的漏洞管理得那么好吗?

答:

2赞 Vlad from Moscow 1/24/2022 #1

对于初学者,数组没有赋值运算符

okunankart = rfid.uid.uidByte[];

无论如何,带有空括号的表达式是错误的。

此声明中的初始值设定项

byte okunankart[4] = rfid.uid.uidByte[];

也是错的。

您需要将元素从一个数组复制到另一个数组中,例如使用标准算法或 C 函数。std::copymemcpy

评论

0赞 koray.gnsl 1/24/2022
我正在更新代码。请检查这个。但这次点亮 ''' String tarih = String(String(myRTC.dayofmonth) + “:” + String(myRTC.month) + “:” + String(myRTC.year);```
0赞 Vlad from Moscow 1/24/2022
@koray.gnsl 你应该这样做。否则,问题和答案只会让读者感到困惑。您应该关闭此问题并提出描述新问题的新问题。在尖线中,删除前导 String(