@hans I also found that I can use attached interrupt for the pin 9 of the coin slots but the problem what line of code to delete and where can I insert the attached interrupt to the coin code?
example
const byte ledPin = 13;
const byte interruptPin = 2;
volatile byte state = LOW;
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(interruptPin, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(interruptPin), blink, CHANGE);
}
void loop() {
digitalWrite(ledPin, state);
}
void blink() {
state = !state;
my code
#include <Adafruit_Fingerprint.h> //Libraries needed
#include <SoftwareSerial.h>
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
#include <EEPROM.h>
#define coinSlot 9 // coinslot 5v to 0v if coin passes on the sensor
#define I2C_ADDR 0x27 //LCD i2c stuff
#define BACKLIGHT_PIN 3
#define En_pin 2
#define Rw_pin 1
#define Rs_pin 0
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7
int relayPin = 4;
String Names[] = { "RAVEN", "Surtr", "Tech",}; //Those are the names affected to the fingertemplates IDs
//The first on which is Names[0] : "" has the ID 1 in the fingerprint sensor
SoftwareSerial mySerial(2, 3); //Fingerprint sensor wiring RX 3, TX 2
LiquidCrystal_I2C lcd(I2C_ADDR, En_pin, Rw_pin, Rs_pin, D4_pin, D5_pin, D6_pin, D7_pin); //LCD declaring
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial); //Fingerprint sensor declaring
volatile int coinCount = 0;
int requiredCoins = 1;
boolean coinInserted = false;
void setup()
{
pinMode(relayPin, OUTPUT);
digitalWrite(relayPin, HIGH);
pinMode(coinSlot, INPUT_PULLUP);
lcd.write(EEPROM.read(5));
Serial.begin(9600);
attachInterrupt(digitalPinToInterrupt(9), coinInterrupt, FALLING);
finger.begin(57600); //Sensor baude rate
lcd.begin (16, 2);
lcd.setBacklightPin(BACKLIGHT_PIN, POSITIVE);
lcd.setBacklight(HIGH);
lcd.setCursor(0, 0);
lcd.print("SECURED VAULT");
lcd.home();
finger.getTemplateCount(); //Counts the number of templates stored in the sensor flash memory
delay(2000);
}
void loop() {
int FingerPrintResult = getFingerprintIDez();
if (FingerPrintResult != -1) { //This function keeps looping and waiting for a fingerprint to be put on the sensor
OpenDoor();
}
else
{
coinSlotSignal = digitalRead(coinSlot);
if (coinInserted) {
coinInserted = false;
coinCount++;
EEPROM.write(0, coinCount);
Serial.println(EEPROM.read(0));
lcd.setCursor(0, 0);
lcd.print("TOTAL:");
lcd.setCursor(0, 1);
lcd.print(coinCount);
}
void coinSlot() {
coinCount++ ;
insert = true;
else {
lcd.clear();
}
}
}
}
//Only the modifications are commented
int getFingerprintIDez() {
uint8_t p = finger.getImage(); //Image scanning
if (p != FINGERPRINT_OK) return -1;
p = finger.image2Tz(); //Converting
if (p != FINGERPRINT_OK) return -1;
lcd.clear(); //And here we write a message or take an action for the denied template
p = finger.fingerFastSearch(); //Looking for matches in the internal memory
if (p != FINGERPRINT_OK) { //if the searching fails it means that the template isn't registered
lcd.print("Access denied");
delay(2000);
return -1;
}
//If we found a match we proceed in the function
lcd.print("Welcome"); //Printing a message for the recognized template
lcd.setCursor(2, 1);
lcd.print(Names[finger.fingerID - 1]); //Then print the name we gave it and the -1 is to remove the shift as the ID starts from "1" but the array from "0"
return finger.fingerID;
}
void OpenDoor() {
digitalWrite(relayPin, LOW); // turn on solenoidlock
delay(5000);
digitalWrite(relayPin, HIGH); // turn off solenoidlock
}
But I got so many error also.
C:\Users\asus\Documents\MARVE THESIS\2_whilelloops\2_whilelloops\2_whilelloops.ino: In function 'void setup()':
2_whilelloops:42:45: error: 'coinInterrupt' was not declared in this scope
attachInterrupt(digitalPinToInterrupt(9), coinInterrupt, FALLING);
^~~~~~~~~~~~~
C:\Users\asus\Documents\MARVE THESIS\2_whilelloops\2_whilelloops\2_whilelloops.ino:42:45: note: suggested alternative: 'noInterrupts'
attachInterrupt(digitalPinToInterrupt(9), coinInterrupt, FALLING);
^~~~~~~~~~~~~
noInterrupts
C:\Users\asus\Documents\MARVE THESIS\2_whilelloops\2_whilelloops\2_whilelloops.ino: In function 'void loop()':
2_whilelloops:63:5: error: 'coinSlotSignal' was not declared in this scope
coinSlotSignal = digitalRead(coinSlot);
^~~~~~~~~~~~~~
C:\Users\asus\Documents\MARVE THESIS\2_whilelloops\2_whilelloops\2_whilelloops.ino:63:5: note: suggested alternative: 'coinSlot'
coinSlotSignal = digitalRead(coinSlot);
^~~~~~~~~~~~~~
coinSlot
2_whilelloops:10:18: error: expected unqualified-id before numeric constant
#define coinSlot 9 // coinslot 5v to 0v if coin passes on the sensor
^
C:\Users\asus\Documents\MARVE THESIS\2_whilelloops\2_whilelloops\2_whilelloops.ino:78:10: note: in expansion of macro 'coinSlot'
void coinSlot() {
^~~~~~~~
Multiple libraries were found for "Adafruit_Fingerprint.h"
Used: C:\Users\asus\Documents\Arduino\libraries\Adafruit_Fingerprint_Sensor_Library
Not used: C:\Users\asus\Documents\Arduino\libraries\fing
exit status 1
'coinInterrupt' was not declared in this scope