Hello
i'm getting an "expression cannot be used as a function" error
i tried to but i cant find the error
thanks in advance
Here's the code:
#include <Stepper.h> //Líbrería para el motorcito
#include <Keypad.h> //Librería para el Keypad
#include <LiquidCrystal_I2C.h> //Líbrería para la pantalla
#include <MFRC522.h> // Líbreria para el RFID
#include <EEPROM.h>
#include <EasyBuzzer.h> //buzzer
//incluye las librerías necesarias
#define I2C_ADDR 0x27 //direccion hexadecimal i2c
#define LCD_COLUMNS 20 //columnas lcd
#define LCD_LINES 4 //Lineas del lcd
#define SS_PIN 10 //pin ss del Rfid
#define RST_PIN 9 //pin Reset del RFID
#define DEFAULT_AMOUNT 2
//
//
bool isBlocked;
bool menu;
int lastProduct;
int tiempo;
const int steps = 1000;
const int buzzerPin = 17; // Define el pin para el buzzer
byte num_rfid = EEPROM.read(0);
unsigned int frequency = 1000;
unsigned int duration = 100;
Stepper motor(steps, A4, A3, A2, A1);
Stepper motor1(steps,A3, A3, A3, A3);
LiquidCrystal_I2C lcd(I2C_ADDR, LCD_COLUMNS, LCD_LINES);
int creditos = 0;
MFRC522 rfid(SS_PIN, RST_PIN); // Instance of the class
MFRC522::MIFARE_Key key;
// Init array that will store new NUID
byte nuidPICC[4];
byte readCard[4];
int successRead;
const byte ROWS = 4;
const byte COLS = 4;
char hexaKeys[ROWS][COLS] = {
{ '1', '2', '3', 'A' },
{ '4', '5', '6', 'B' },
{ '7', '8', '9', 'C' },
{ '*', '0', '#', 'D' }
};
byte rowPins[ROWS] = { 9, 8, 7, 6 };
byte colPins[COLS] = { 5, 4, 3, 2 };
Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
void agregarTag(byte* uid){
}
void setup() {
Serial.begin(9600); // Comienza la comunicación serial
motor.setSpeed(60);
motor1.setSpeed(60);
lcd.init();
lcd.backlight();
SPI.begin();
rfid.PCD_Init();
Serial.println("Lector de RFID listo");
pinMode(14, INPUT_PULLUP);
pinMode(15, INPUT_PULLUP); // el eclipse no fue parcial y cegoooo nuestras miradas te vi q llorabas te vi q llorabas x el te para tres
pinMode(16, INPUT_PULLUP);
for (byte i = 0; i < 6; i++) {
key.keyByte[i] = 0xFF;
}
if ( ! rfid.PICC_IsNewCardPresent())
return;
// Verify if the NUID has been readed
if ( ! rfid.PICC_ReadCardSerial())
return;
EasyBuzzer.singleBeep(
frequency, // Frequency in hertz(HZ).
duration // Duration of the beep in milliseconds(ms).
);
}
void loop() {
EasyBuzzer.update();
bool CreditosMas = digitalRead(14);
bool CreditosMenos = digitalRead(15);
bool EEPGONExd = digitalRead(16);
if(isBlocked == false){
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Bienvenido!");
lcd.setCursor(0, 1);
lcd.print("Sus creditos:");
lcd.setCursor(14, 1);
lcd.print(creditos);
delay(20);
menu = 1;
}
//Con mi balsa yo me ire a naufragaaaaaaaar
if (rfid.PICC_IsNewCardPresent() && rfid.PICC_ReadCardSerial()) {
int uidIndex = findUIDIndex();
if (uidIndex != -1) {
creditos++;
}
}
if(CreditosMas == 0){
creditos++;
delay(150);
}
if(CreditosMenos == 0){
creditos = creditos - 1;
delay(150);
} // Y GRACIAS POR VENIIR
if(EEPGONExd == 0){
for (int i = 0 ; i < EEPROM.length() ; i++) {
EEPROM.write(i, 0);
}
}
char customKey = customKeypad.getKey();
if (customKey == 'A') {
EasyBuzzer.singleBeep(frequency, duration);
menu = 0;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Usted eligio:");
lcd.setCursor(0, 1);
lcd.print("Producto A");
isBlocked = 1;
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Confirmar con #");
Serial.print("Cancelar con #");
lcd.setCursor(0, 1);
lcd.print("Cancelar con *");
Serial.print("Cancelar con *");
lastProduct = 1;
} else if (customKey == 'B') {
EasyBuzzer.singleBeep(frequency, duration);
tiempo = millis();
menu = 0;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Usted eligio:");
lcd.setCursor(0, 1);
lcd.print("Producto B");
isBlocked = 1;
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Confirmar con #");
Serial.print("Confirmar con #");
lcd.setCursor(0, 1);
lcd.print("Cancelar con *");
Serial.print("Cancelar con *");
delay(2000);
lastProduct = 2;
if(tiempo >= 30000){
menu = 0;
isBlocked = 0;
}
}
if(customKey == '#' && lastProduct == 1 && creditos >= 3){
EasyBuzzer.singleBeep(frequency, duration);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Compra aceptada");
Serial.print("Compra aceptada");
lcd.setCursor(0, 1);
lcd.print("Producto 1");
Serial.print("Producto 1");
motor.step(steps);
lastProduct == 0;
creditos = creditos-3;
}else if (customKey == '*' && lastProduct == 1 && menu == 0){
EasyBuzzer.singleBeep(frequency, duration);
lcd.clear();
lcd.print("Compra cancelada.");
Serial.print("Compra cancelada.");
delay(2000);
isBlocked = 0;
lastProduct == 0;
}else if(customKey == '#' && lastProduct == 1 && creditos <= 3 && menu == 0){
EasyBuzzer.singleBeep(frequency, duration);
lcd.clear();
lcd.print("Creditos insuficientes");
delay(2000);
isBlocked = 0;
lastProduct == 0;
}
if (customKey == '#' && lastProduct == 2 && creditos >= 3 && menu == 0) {
EasyBuzzer.singleBeep(frequency, duration);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Compra aceptada");
Serial.print("Compra aceptada");
lcd.setCursor(0, 1);
lcd.print("Producto 2");
Serial.print("Producto 2");
motor1.step(steps);
creditos = creditos-3;
lastProduct == 0;
}else if(customKey == '#' && lastProduct == 2 && creditos <= 3 && menu == 0){
EasyBuzzer.singleBeep(frequency, duration);
lcd.clear();
lcd.print("Creditos insuficientes");
delay(2000);
isBlocked = 0;
lastProduct == 0;
}
if(customKey == '*' && lastProduct == 2 && menu == 0 && menu == 0) {
EasyBuzzer.singleBeep(frequency, duration);
lcd.clear();
lcd.print("Compra cancelada.");
Serial.print("Compra cancelada.");
delay(2000);
isBlocked = 0;
lastProduct == 0;
}
// Reset the loop if no new card present on the sensor/reader. This saves the entire process when idle.
// Verify if the NUID has been readed
if ( ! rfid.PICC_ReadCardSerial())
return;
Serial.print(F("PICC type: "));
MFRC522::PICC_Type piccType = rfid.PICC_GetType(rfid.uid.sak);
Serial.println(rfid.PICC_GetTypeName(piccType));
// Check is the PICC of Classic MIFARE type
if (piccType != MFRC522::PICC_TYPE_MIFARE_MINI &&
piccType != MFRC522::PICC_TYPE_MIFARE_1K &&
piccType != MFRC522::PICC_TYPE_MIFARE_4K) {
Serial.println(F("Your tag is not of type MIFARE Classic."));
return;
}
if (rfid.uid.uidByte[0] != nuidPICC[0] ||
rfid.uid.uidByte[1] != nuidPICC[1] ||
rfid.uid.uidByte[2] != nuidPICC[2] ||
rfid.uid.uidByte[3] != nuidPICC[3] ) {
Serial.println(F("A new card has been detected."));
// Store NUID into nuidPICC array
for (byte i = 0; i < 4; i++) {
nuidPICC[i] = rfid.uid.uidByte[i];
}
Serial.println(F("The NUID tag is:"));
Serial.print(F("In hex: "));
printHex(rfid.uid.uidByte, rfid.uid.size);
Serial.println();
Serial.print(F("In dec: "));
printDec(rfid.uid.uidByte, rfid.uid.size);
Serial.println();
}
else Serial.println(F("Card read previously."));
// Halt PICC
rfid.PICC_HaltA();
// Stop encryption on PCD
rfid.PCD_StopCrypto1();
for (int i = 0; i < rfid.uid.size; i++) { //imprime eemprom cada vez que se lee rfid
readCard[i] = rfid.uid.uidByte[i];
EEPROM.write(i+1(rfid.uid.size*num_rfid), readCard[i] );
Serial.print(readCard[i], HEX);
}
num_rfid++; //añadimos 1 al contador en la EEPROM
EEPROM.write(0,num_rfid);
}
int findUIDIndex() {
for (int i = 0; i < EEPROM.length(); i += 5) {
if (EEPROM.read(i) == rfid.uid.uidByte[0] && EEPROM.read(i + 1) == rfid.uid.uidByte[1] && EEPROM.read(i + 2) == rfid.uid.uidByte[2] && EEPROM.read(i + 3) == rfid.uid.uidByte[3]) {
return i;
}
}
return -1;
}
void printHex(byte *buffer, byte bufferSize) {
for (byte i = 0; i < bufferSize; i++) {
Serial.print(buffer[i] < 0x10 ? " 0" : " ");
Serial.print(buffer[i], HEX);
}
}
/**
* Helper routine to dump a byte array as dec values to Serial.
*/
void printDec(byte *buffer, byte bufferSize) {
for (byte i = 0; i < bufferSize; i++) {
Serial.print(buffer[i] < 0x10 ? " 0" : " ");
Serial.print(buffer[i], DEC);
}
}