0

enter image description here

#include <Adafruit_Fingerprint.h>
#include  <SoftwareSerial.h>
#include <LiquidCrystal.h>

uint8_t id;
int getFingerprintIDez();
//pin #16 is IN from sensor (GREEN wire)
//pin #15 is OUT from arduino (WHITE wire)
int Contrast = 100;
SoftwareSerial mySerial(52, 16);
LiquidCrystal lcd(13, 12, 11, 10, 9, 8); // initialize the library with the numbers of the interface pins
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);
#define S1 22 //Button candidate A
#define S2 24 // Button candidate B
#define S3 26 // Button candidate c
#define S4 28 // Button candidate D
#define S5 30 // Button Result
#define S6 2 // Button submit
#define S7 32 // Button to cast vote
int can1 = 0;
int can2 = 0;
int can3 = 0;
int can4 = 0;
int total;
SoftwareSerial ESP8266(50, 18);// RX, TX

void setup() { 
  Serial.begin(9600); // initialize the serial communications:
  lcd.begin(16, 2); lcd.clear();
  lcd.print("  Polling Day  ");
  lcd.setCursor(0, 1);
  lcd.print("      UPM      ");
  delay(2000);

  mainpage();

  pinMode(13, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(A0, INPUT);

  finger.begin(57600); // set the data rate for the sensor serial port

  pinMode(S1, INPUT);
  pinMode(S2, INPUT);
  pinMode(S3, INPUT);
  pinMode(S4, INPUT);
  pinMode(S5, INPUT);
  pinMode(S6, INPUT);
  pinMode(S7, INPUT);

  ESP8266.begin(9600);

  digitalWrite(S1, HIGH);
  digitalWrite(S2, HIGH);
  digitalWrite(S3, HIGH);
  digitalWrite(S4, HIGH);
  digitalWrite(S5, HIGH);
  digitalWrite(S6, HIGH);
  digitalWrite(S7, HIGH);

  SendCommand("AT+RST", "Ready");
  delay(5000);
  SendCommand("AT+CWMODE=1", "OK");
  SendCommand("AT+CIFSR", "OK");
  SendCommand("AT+CIPMUX=1", "OK");
  SendCommand("AT+CIPSERVER=1,80", "OK");
}

void loop() { // run over and over again
  getFingerprintID();
  delay(100);
  digitalWrite (13, HIGH);
  if (digitalRead(S5) == 0) { // To view the result for admin only
    int total = can1 + can2 + can3 + can4;
    lcd.clear();
    lcd.setCursor(1, 0);
    lcd.print("1");
    lcd.setCursor(1, 1);
    lcd.print(can1);
    lcd.setCursor(5, 0);
    lcd.print("2");
    lcd.setCursor(5, 1);
    lcd.print(can2);
    lcd.setCursor(9, 0);
    lcd.print("3");
    lcd.setCursor(9, 1);
    lcd.print(can3);
    lcd.setCursor(13, 0);
    lcd.print("4");
    lcd.setCursor(13, 1);
    lcd.print(can4);
    delay(4000);
    if (total) {
      if ((can1 > can2 && can1 > can3 && can1 > can4)) {
        lcd.clear();
        lcd.print("Can A is Winner");
        delay(3000);
        lcd.clear();
      } else if ((can2 > can1 && can2 > can3 && can2 > can4)) {
        lcd.clear();
        lcd.print("Can B is Winner");
        delay(3000);
        lcd.clear();
      } else if ((can3 > can1 && can3 > can2 && can3 > can4)) {
        lcd.clear();
        lcd.print("Can C is Winner");
        delay(3000);
        lcd.clear();
      } else if (can4 > can1 && can4 > can2 && can4 > can3) {
        lcd.setCursor(0, 0);
        lcd.clear();
        lcd.print("Can D is Winner");
        delay(3000);
        lcd.clear();
      } else if (can4 > can1 && can4 > can2 && can4 > can3) {
        lcd.setCursor(0, 0);
        lcd.clear();
        lcd.print("Can D is Winner");
        delay(3000);
        lcd.clear();
      } else {
        lcd.clear();
        lcd.print(" Tie Up Or ");
        lcd.setCursor(0, 1);
        lcd.print(" No Result ");
        delay(3000);
        lcd.clear();
      }
    } else {
      lcd.clear();
      lcd.print("No Voting....");
      delay(3000);
      lcd.clear();
    }
    can1 = 0; can2 = 0; can3 = 0; can4 = 0, total = 0;
    lcd.clear();
    adminpage();
  }

  if (digitalRead(S7) == 0) { //To cast avote for user
    voterpage();
  }

  if (digitalRead(S1) == 0) {
    can1++;
    votereceived();
    mainpage();
  }

  while (digitalRead(S1) == 0);
  if (digitalRead(S2) == 0) {
    can2++;
    votereceived();
    mainpage();
  }
  while (digitalRead(S2) == 0);
  if (digitalRead(S3) == 0) {
    can3++;
    votereceived();
    mainpage();
  }
  while (digitalRead(S3) == 0);
  if (digitalRead(S4) == 0) {
    can4++;
    votereceived();
    mainpage();
  }
  while (digitalRead(S4) == 0);
  if (digitalRead(S6) == 0) {
    lcd.clear();
    lcd.print("Submitting...");
    delay(1000);
    ESP8266.println("AT+CIPSEND=0,23");
    delay(1000);
    SendCommand("AT+CIPCLOSE=0", "OK");
  }
  String IncomingString = "";
  boolean StringReady = false;

  while (ESP8266.available()) {
    IncomingString = ESP8266.readString();
    StringReady = true;
  }

  if (StringReady) {
    Serial.println("Received String: " + IncomingString);

    if (IncomingString.indexOf("LED=ON") != -1) {
      digitalWrite(LED, HIGH);
    }

    if (IncomingString.indexOf("LED=OFF") != -1) {
      digitalWrite(LED, LOW);
    }
  }

  boolean SendCommand(String cmd, String ack) {
    ESP8266.println(cmd); // Send "AT+" command to module
    if (!echoFind(ack)) // timed out waiting for ack string
      return true; // ack blank or ack found
  }

  boolean echoFind(String keyword) {
    byte current_char = 0;
    byte keyword_length = keyword.length();
    long deadline = millis() + TIMEOUT;
    while (millis() < deadline) {
      if (ESP8266.available()) {
        char ch = ESP8266.read();
        Serial.write(ch);
        if (ch == keyword[current_char])
          if (++current_char == keyword_length) {
            Serial.println();
            return true;
          }
      }
    }
    return false; // Timed out
  }
}

uint8_t getFingerprintID() { 
  uint8_t p = finger.getImage();
  switch (p) {
    case FINGERPRINT_OK:
      lcd.clear();
      lcd.print(" Image taken... ");
      delay(1000);
      break;
    case FINGERPRINT_NOFINGER:
      return p;
    case FINGERPRINT_PACKETRECIEVEERR:
      return p;
    case FINGERPRINT_IMAGEFAIL:
      return p;
    default:
      return p;
  }

  // OK success!
  p = finger.image2Tz();
  switch (p) {
    case FINGERPRINT_OK:
      break;
    case FINGERPRINT_IMAGEMESS:
      return p;
    case FINGERPRINT_PACKETRECIEVEERR:
      return p;
    case FINGERPRINT_FEATUREFAIL:
      return p;
    case FINGERPRINT_INVALIDIMAGE:
      return p;
    default:
      return p;
  }

  // OK converted!
  p = finger.fingerFastSearch();
  if (p == FINGERPRINT_OK) {
    if (finger.fingerID == 26) {
      lcd.clear();
      lcd.setCursor(1, 0);
      lcd.print("Redirecting to");
      lcd.setCursor(1, 1);
      lcd.print("Admin process");
    } else {
      lcd.clear();
      lcd.setCursor(2, 0);
      lcd.print("Valid Voter!");
      lcd.setCursor(2, 1);
      lcd.print("ID : ");
      lcd.print(finger.fingerID);
    }

    digitalWrite(11, HIGH);
    delay(1000);
    digitalWrite(11, LOW); // turn on green LED to indicate match
  } else if (p == FINGERPRINT_NOTFOUND) {
    lcd.clear();
    lcd.setCursor(1, 0);
    lcd.print("Unregistered");
    lcd.setCursor(3, 1);
    lcd.print("Voter!");
    delay(1000);
    lcd.clear();
    lcd.setCursor(2, 0);
    lcd.print("scan finger");
    lcd.setCursor(6, 1);
    lcd.print("again");
    return p;
  } else {
    return p;
  }

  // IF FOUND A MATCH............
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Found ID #");

  if (finger.fingerID == 26) {
    adminpage();
  } else {
    voterpage();
  }
}

// returns -1 if failed, otherwise returns ID #
int getFingerprintIDez() {
  uint8_t p = finger.getImage();
  if (p != FINGERPRINT_OK) return -1;
  p = finger.image2Tz();
  if (p != FINGERPRINT_OK) return -1;
  p = finger.fingerFastSearch();
  if (p != FINGERPRINT_OK) return -1;
  // found a match!
  digitalWrite(13, LOW);
  delay(10);
  digitalWrite(13, HIGH);
  delay(10);
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Found ID # ");
  lcd.print(finger.fingerID);
  lcd.setCursor(0, 1);
  lcd.print("confidence ");
  lcd.print(finger.confidence);
  return finger.fingerID;
}

void voterpage() {
  lcd.clear();
  lcd.setCursor(1, 0);
  lcd.print("Candidate 1");
  lcd.setCursor(1, 1);
  lcd.print("Mohd Faiz");
  delay(3000);
  lcd.clear();
  lcd.setCursor(1, 0);
  lcd.print("Candidate 2");
  lcd.setCursor(1, 1);
  lcd.print("Siti Nur Ila");
  delay(3000);
  lcd.clear();
  lcd.setCursor(1, 0);
  lcd.print("Candidate 3");
  lcd.setCursor(1, 1);
  lcd.print("Muhammad Aus");
  delay(3000);
  lcd.clear();
  lcd.setCursor(1, 0);
  lcd.print("Candidate 4");
  lcd.setCursor(1, 1);
  lcd.print("Wan zakaria");
  delay(3000);
  lcd.clear();
  lcd.setCursor(1, 0);
  lcd.print("Choose 1 only");
  lcd.setCursor(1, 1);
  lcd.print("1");
  lcd.setCursor(5, 1);
  lcd.print("2");
  lcd.setCursor(9, 1);
  lcd.print("3");
  lcd.setCursor(13, 1);
  lcd.print("4");
}

void votereceived() {
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Vote Received");
  lcd.setCursor(2, 1);
  lcd.print("Thank You :)");
  delay(2000);
}

void adminpage() {
  lcd.clear();
  lcd.setCursor(3, 0);
  lcd.print("1");
  lcd.setCursor(1, 1);
  lcd.print("Result");
  lcd.setCursor(11, 0);
  lcd.print("2");
  lcd.setCursor(8, 1);
  lcd.print(" Submit");
  delay(2000);
}

void mainpage() {
  lcd.clear(); lcd.setCursor(0, 0); lcd.print("Scan your finger");
}
5
  • I guess you don't have a SendCommand() function in your code. Though we cannot know. Please show the complete code as text (by copy&pasting it). Also copy the complete error output into the question, including the line, where the error happens
    – chrisl
    Dec 15, 2020 at 13:10
  • @chrisl Hi here my complete code. appreciated if you could detect where my error was. Dec 15, 2020 at 14:12
  • 1
    Please no text as images. You can copy the text inside the compilation output field (where the error message show up) and copy it in your question as text. That makes it way better to read
    – chrisl
    Dec 15, 2020 at 14:14
  • 1
    The problem is, that you try to define functions inside of other functions. The SendCommand() function is currently definied inside the loop() function, which is not allowed. Move all function definitions at the lowest level (alongside the loop() function, not in it). BTW: The autoformat function of the Arduino IDE is your friend. I formatted your code, so that you can easier see, where the functions are placed.
    – chrisl
    Dec 15, 2020 at 14:25
  • Though, this is a pure programming error. As I wrote the solution in the comments, I'm now voting to close this question, as it is not about Arduino. Have fun with your project :)
    – chrisl
    Dec 15, 2020 at 14:26

1 Answer 1

2

Both boolean SendCommand() and boolean echoFind() are defined inside loop(), and they shouldn't be; it is not allowed to define functions inside functions.

Take them out of loop() and define them at (move them to) the same level as uint8_t getFingerprintID(), etc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.