Este es el esperado vídeo de presentación de nuestra maqueta.

Ha sido un largo camino desde que en 2015 en el departamento de Edificación pensaron en reconstruir a partir de fotos una maqueta del Picasso de la plaza de la Merced de Málaga. Años después tomo un nuevo camino a partir de conversaciones de pasillo con los de Electrónica para germinar una idea que se fue materializando en prácticas con los alumnos y finalmente el diseño 3D, la fabricación y puesta a punto del dispositivo final.

Hoy ya es un juguetito que llama la atención cuando lo sacamos a pasear por los pasillos.

Código final:

//PLACA LOLIN(WEMOS) D1 R2 & mini
//JSON a incluir en preferencias: http://arduino.esp8266.com/stable/package_esp8266com_index.json

#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h"

const int PIN_SENSOR = A0;
SoftwareSerial mySoftwareSerial(D1, D2); // RX, TX
DFRobotDFPlayerMini myDFPlayer;

// Configuraciones de sensor
const int UMBRAL = 300; // Umbral para que active o no
unsigned int lecturaSENSOR = 0; // Estado inicial

const int ANTIRREBOTE = 300;
const int TIMER_ENG = 500; // Umbral para determinar si es short o long Tap

boolean sensor_on = false; // Booleano para detectar activacion de sensor
boolean sensor_hold = false; // Booleano para detectar activacion sostenida del sensor
boolean play = false; // Booleano para saber si se esta reproduciendo
unsigned long startTime;
unsigned long runningTime;
unsigned long tapTime;

void leerSENSOR() // Función para la lectura del sensor
{
lecturaSENSOR = analogRead(PIN_SENSOR);

if (lecturaSENSOR > UMBRAL) {
sensor_on = true;
} else {
sensor_on = false;
}
}

void setupDFPlayer() // Función para el arranque del reproductor de audio
{
mySoftwareSerial.begin(9600);
Serial.println("SETUP");
Serial.println(F("Initializing DFPlayer ... (May take 3~5 seconds)"));

if (!myDFPlayer.begin(mySoftwareSerial)) { //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."));

myDFPlayer.setTimeOut(500); //Set serial communication time out 500ms

//----Set volume----
myDFPlayer.volume(25); //Set volume value (0~30).
//----Set different EQ----
myDFPlayer.EQ(DFPLAYER_EQ_NORMAL);
//----Set device we use SD as default----
// myDFPlayer.outputDevice(DFPLAYER_DEVICE_U_DISK);
myDFPlayer.outputDevice(DFPLAYER_DEVICE_SD);
}

unsigned long getTapTime() {
if (sensor_on && startTime == 0) { //sensor tapado
Serial.println("sensor tapado");
startTime = millis();
}
if (!sensor_on && startTime != 0) { //sensor liberado
Serial.println("sensor liberado");
runningTime = millis();
}
if (runningTime != 0) {
tapTime = runningTime - startTime;
Serial.print("tapTime: ");
Serial.println(tapTime);
startTime = 0;
runningTime = 0;
}
return tapTime;
}

void setup() {
Serial.begin(115200);
setupDFPlayer();
startTime = 0;
runningTime = 0;
pinMode(PIN_SENSOR, INPUT);
}
void loop() {
leerSENSOR(); // control del sensor
getTapTime(); // medir tiempos
if (tapTime != 0) {
if (tapTime < TIMER_ENG) {
Serial.println("shortTap");
if (!play) {
play = true;
myDFPlayer.play(1); //Play the first mp3 (ES)
} else {
play = false;
myDFPlayer.pause(); //Pause mp3
}
delay(ANTIRREBOTE);
} else {
Serial.println("longTap");
if (!play) {
play = true;
myDFPlayer.play(2); //Play the second mp3 (EN)
}
delay(ANTIRREBOTE);
}
tapTime = 0;
}
}