Este es el código completo del proyecto..... Como veis he intentado hacer de todo, pero no va
#include "Arduino.h"
#include "HX711.h"
#include <Keypad.h>
#include "DFRobotDFPlayerMini.h"
//#include "DFRobotDFPlayerMini2.h"
#include "SoftwareSerial.h"
// Parámetro para calibrar el peso y el sensor
#define CALIBRACION -1440
const byte rowsCount = 4;
const byte columsCount = 3;
const byte rowPins[rowsCount] = { 41, 39, 37, 35 };
const byte columnPins[columsCount] = { 29, 31, 33 };
int ledRojo=12; // pin para el LED rojo
int luzpolicia=14;
int interruptor=9;
char numeroTelefono[10] = {'9', '1', '4', '6', '2', '5', '5', '2', '0', '7'};
char myDial[10];
int posicion=0; // necesaria para la clave
int cursor=0; // posicion inicial de la clave
int clave=0; // para el LCD
int value=0; // para interruptor
int correcto=0;
int peso=0; // Lectura peso
bool pesocorrecto=false;
bool timbre=false;
// millis
unsigned long tiempo1 = 0;
unsigned long tiempo2 = 0;
unsigned long tiempoSegundos = 0;
// Pin de datos y de reloj
byte pinData = 22;
byte pinClk = 24;
// Objeto HX711
HX711 balanza;
//DFPlayer 1 AURICULAR TELEFONO
SoftwareSerial myAuricular(10, 11); // RX, TX
DFRobotDFPlayerMini mySonidoAuricular;
//DFPlayer 1 ALTAVOZ
SoftwareSerial myAltavoz(5, 6); // RX, TX
DFRobotDFPlayerMini mySonidoAltavoz;
void printDetail(uint8_t type, int value);
char keys[rowsCount][columsCount] = {
{ '1','2','3', },
{ '4','5','6', },
{ '7','8','9', },
{ '#','0','*', }
};
// teclado
Keypad keypad = Keypad(makeKeymap(keys), rowPins, columnPins, rowsCount, columsCount);
void setup() {
Serial.begin(9600);
Serial.println(F("Comunicación Serial arrancada"));
// Iniciar sensor
balanza.begin(pinData, pinClk);
// Aplicar la calibración
balanza.set_scale(CALIBRACION);
// Iniciar la tara
// No tiene que haber nada sobre el peso
balanza.tare();
// Iniciar DFPlayer 1
myAuricular.begin(9600);
myAuricular.listen();
Serial.println();
Serial.println(F("DFRobot DFPlayer Mini Demo"));
Serial.println(F("Initializing DFPlayer AURICULAR... (May take 3~5 seconds)"));
if (!mySonidoAuricular.begin(myAuricular))
{ //Use softwareSerial to communicate with mp3.
Serial.println(F("Unable to begin:"));
Serial.println(F("1.Please recheck the connection!"));
Serial.println(F("2.Please insert the SD card!"));
while(true);
}
Serial.println(F("DFPlayer Mini online."));
mySonidoAuricular.setTimeOut(500); //Set serial communictaion time out 500ms
//----Set volume----
mySonidoAuricular.volume(15); //Set volume value (0~30).
mySonidoAuricular.volumeUp(); //Volume Up
mySonidoAuricular.volumeDown(); //Volume Down
//----Set different EQ----
mySonidoAuricular.EQ(DFPLAYER_EQ_NORMAL);
mySonidoAuricular.outputDevice(DFPLAYER_DEVICE_SD);
//----Read imformation----
Serial.println(mySonidoAuricular.readState()); //read mp3 state
Serial.println(mySonidoAuricular.readVolume()); //read current volume
Serial.println(mySonidoAuricular.readEQ()); //read EQ setting
Serial.println(mySonidoAuricular.readFileCounts()); //read all file counts in SD card
Serial.println(mySonidoAuricular.readCurrentFileNumber()); //read current play file number
Serial.println(mySonidoAuricular.readFileCountsInFolder(1)); //read fill counts in folder SD:/03
delay(1000);
// Iniciar DFPlayer 2
myAltavoz.begin(9600);
myAltavoz.listen();
Serial.println();
Serial.println(F("DFRobot DFPlayer Mini Demo"));
Serial.println(F("Initializing DFPlayer ALTAVOZ... (May take 3~5 seconds)"));
if (!mySonidoAuricular.begin(myAltavoz))
{ //Use softwareSerial to communicate with mp3.
Serial.println(F("Unable to begin:"));
Serial.println(F("1.Please recheck the connection!"));
Serial.println(F("2.Please insert the SD card!"));
while(true);
}
Serial.println(F("DFPlayer Mini online."));
mySonidoAltavoz.setTimeOut(500); //Set serial communictaion time out 500ms
//----Set volume----
mySonidoAltavoz.volume(25); //Set volume value (0~30).
mySonidoAltavoz.volumeUp(); //Volume Up
mySonidoAltavoz.volumeDown(); //Volume Down
//----Set different EQ----
mySonidoAltavoz.EQ(DFPLAYER_EQ_NORMAL);
mySonidoAltavoz.outputDevice(DFPLAYER_DEVICE_SD);
//----Read imformation----
Serial.println(mySonidoAltavoz.readState()); //read mp3 state
Serial.println(mySonidoAltavoz.readVolume()); //read current volume
Serial.println(mySonidoAltavoz.readEQ()); //read EQ setting
Serial.println(mySonidoAltavoz.readFileCounts()); //read all file counts in SD card
Serial.println(mySonidoAltavoz.readCurrentFileNumber()); //read current play file number
Serial.println(mySonidoAltavoz.readFileCountsInFolder(1)); //read fill counts in folder SD:/03
delay(1000);
pinMode (ledRojo, OUTPUT);
//pinMode (luzpolicia, OUTPUT);
//digitalWrite(luzpolicia, LOW);
pinMode (interruptor, INPUT_PULLUP);
}
void loop() {
Serial.print("[HX7] Leyendo: ");
peso=balanza.get_units(20);
Serial.print("PESO: ");
Serial.print(peso);
Serial.print(" gr");
Serial.println();
// Comprobar si el peso es correcto
if ((peso>10) && (peso<20) || pesocorrecto)
{
Serial.println("PESO CORRECTO FALSO");
pesocorrecto=true;
Serial.println("PESO CORRECTO...");
int value = digitalRead(interruptor); //lectura digital de pin
// Comprobar si el led rojo esta encendido (descolgado)
if ((value == LOW) && timbre)
{
mySonidoAuricular.playMp3Folder(4); //Locución al cojer telefono tras timbre
delay(7000);
//mySonidoAltavoz.playMp3Folder(2); //Altavoz Policia
//Encender sirena policia
digitalWrite(luzpolicia, HIGH);
timbre=false;
}
if (value == LOW)
{
Serial.println("Auricular descolgado");
mySonidoAuricular.playMp3Folder(1); //Establecimiento de linea
//delay(1000);
digitalWrite(ledRojo, HIGH);
while (clave == 0)
{
// Leemos teclado telefono
char tecla = keypad.getKey() ; // leemos tecla
if (tecla != 0) //Si el valor es 0 es que no se ha pulsado ninguna tecla
{ // descartamos almohadilla y asterisco
if (tecla != '#' && tecla != '*' && clave==0)
{
cursor++; // incrementamos el cursor
}
}
// Si el carácter leído coincide con el del código secreto
if (tecla == numeroTelefono[posicion])
{
posicion ++; //Incrementa en 1 la posición del código secreto
}
//Si hemos llegado a la posición 10 del código secreto
if (posicion == 10)
{
Serial.println("Numero Telefono correcto");
mySonidoAuricular.playMp3Folder(2); //numero de telefono correcto
delay(7000);
clave=1; // indicamos que se ha introducido la clave
}
//--- En el caso de que este incompleta o no hayamos acertado ----------
if(cursor==10 && clave==0) // comprobamos que no hemos acertado
{
Serial.println("Numero Telefono incorrecto");
mySonidoAuricular.playMp3Folder(3); //numero de telefono erroneo
cursor=0;
delay(7000);
}
}
} else
{
Serial.println("Auricular colgado");
//Auricular colgado
tiempo1 = millis();
digitalWrite(ledRojo, LOW);
Serial.println("Primer Timbre");
//mySonidoAuricular.playMp3Folder(5); //timbre
mySonidoAltavoz.playMp3Folder(1); //Timbre telefono
delay(3000);
timbre=true;
tiempo2 = millis();
if(tiempo2 > (tiempo1+10000)) //Si han pasado 5 segundos desde que se colgó el teléfono
{
Serial.println("Siguientes timbres");
tiempo1 = millis(); //Actualiza el tiempo actual
mySonidoAltavoz.playMp3Folder(1); //Timbre telefono
//mySonidoAuricular.playMp3Folder(5); //timbre
delay(3000);
}
}
}
}