Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
S
scapreroom
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Royo Emperador Paula
scapreroom
Commits
c93e1e00
Unverified
Commit
c93e1e00
authored
Jul 01, 2020
by
paularoyo76
Committed by
GitHub
Jul 01, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add files via upload
parent
0e59fdfd
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
181 additions
and
0 deletions
+181
-0
proyectoFinal.ino
proyectoFinal.ino
+181
-0
No files found.
proyectoFinal.ino
0 → 100644
View file @
c93e1e00
//interrupcionPIR
#include "driver/gpio.h"
#define timeSeconds 10
#define pista2 10
#define pista3 10
const
int
motionSensor
=
32
;
long
now
;
long
lastTrigger
=
0
;
int
startTimer
=
0
;
int
desbloqueo
=
0
;
int
state
=
1
;
int
C
[
5
];
//MiniReproductor MP3
#include "Arduino.h"
#include "DFRobotDFPlayerMini.h"
#include "HardwareSerial.h"
HardwareSerial
mySoftwareSerial
(
1
);
DFRobotDFPlayerMini
myDFPlayer
;
void
printDetail
(
uint8_t
type
,
int
value
);
//Bluetooth
#include "BluetoothSerial.h"
#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
#endif
BluetoothSerial
SerialBT
;
//PULSADOR
int
P1
=
0
;
int
P2
=
0
;
int
P3
=
0
;
int
P4
=
0
;
int
C1
=
0
;
int
C2
=
0
;
int
C3
=
0
;
int
C4
=
0
;
void
setup
()
{
Serial
.
begin
(
115200
);
now
=
millis
();
pinMode
(
17
,
INPUT_PULLUP
);
pinMode
(
18
,
INPUT_PULLUP
);
pinMode
(
19
,
INPUT_PULLUP
);
pinMode
(
5
,
INPUT_PULLUP
);
//Bluetooth
SerialBT
.
begin
(
"ESP32test"
);
//Bluetooth device name
Serial
.
println
((
"The device started, now you can pair it with bluetooth!"
));
//PIR Motion Sensor mode
pinMode
(
motionSensor
,
INPUT_PULLUP
);
attachInterrupt
(
digitalPinToInterrupt
(
motionSensor
),
detectsMovement
,
RISING
);
//indica que se ha detectado movimiento
Serial
.
println
((
"Sensor PIR active"
));
//MP3
mySoftwareSerial
.
begin
(
9600
,
SERIAL_8N1
,
26
,
25
);
// speed, type, RX, TX
Serial
.
println
();
Serial
.
println
((
"DFRobot DFPlayer Mini Demo"
));
myDFPlayer
.
begin
(
mySoftwareSerial
);
Serial
.
println
((
"DFPlayer Mini online."
));
//----Set volume----
myDFPlayer
.
volume
(
25
);
Serial
.
println
(
"Standby"
);
SerialBT
.
println
(
"Standby"
);
//control desde el movil del juego
}
void
loop
()
{
now
=
millis
();
//CONTROL BLUETOOTH -------------------------------------------------------------------------------
if
(
SerialBT
.
available
())
{
//Doy posibilidad de controlar el volumen, iniciar el audio y cambiar al siguente
String
inData
=
" "
;
inData
=
SerialBT
.
readStringUntil
(
'\n'
);
if
(
inData
.
startsWith
(
"+"
)){
SerialBT
.
println
(
F
(
"up..."
));
myDFPlayer
.
volumeUp
();
}
else
if
(
inData
.
startsWith
(
"-"
)){
SerialBT
.
println
(
F
(
"down..."
));
myDFPlayer
.
volumeDown
();
}
else
if
(
inData
.
startsWith
(
"n"
)){
SerialBT
.
println
(
F
(
"next..."
));
myDFPlayer
.
next
();
}
if
(
inData
.
startsWith
(
"C"
)){
for
(
int
i
=
0
;
i
<
5
;
i
++
)
{
int
index
=
inData
.
indexOf
(
','
);
C
[
i
]
=
inData
.
substring
(
0
,
index
).
toInt
();
inData
=
inData
.
substring
(
index
+
1
);
}
C1
=
((
int
)
C
[
1
]);
C2
=
((
int
)
C
[
2
]);
C3
=
((
int
)
C
[
3
]);
C4
=
((
int
)
C
[
4
]);
SerialBT
.
println
(
F
(
"Nuevo código: "
));
SerialBT
.
println
(
C1
,
DEC
);
SerialBT
.
println
(
C2
,
DEC
);
SerialBT
.
println
(
C3
,
DEC
);
SerialBT
.
println
(
C4
,
DEC
);
}
}
//if(SerialBT.available())
//MAQUINA DE ESTADOS ------------------------------------------------------------------------------
switch
(
state
){
case
1
:
//PIR SENSOR
if
(
startTimer
==
1
){
state
=
2
;
SerialBT
.
println
(
"Detectado"
);
}
break
;
case
2
:
myDFPlayer
.
play
(
1
);
P1
=
digitalRead
(
17
);
P2
=
digitalRead
(
5
);
P3
=
digitalRead
(
18
);
P4
=
digitalRead
(
19
);
if
(
P1
==
C1
&&
P2
==
C2
&&
P3
==
C3
&&
P4
==
C4
){
desbloqueo
=
1
;
}
if
(
startTimer
==
1
&&
(
now
-
lastTrigger
>
(
timeSeconds
*
1000
))){
SerialBT
.
print
(
"CUENTA ATRAS ACABADA, la contraseña es: "
);
SerialBT
.
print
(
C1
,
DEC
);
SerialBT
.
print
(
C2
,
DEC
);
SerialBT
.
print
(
C3
,
DEC
);
SerialBT
.
print
(
C4
,
DEC
);
SerialBT
.
print
(
", pero se ha introducido : "
);
SerialBT
.
print
(
P1
,
DEC
);
SerialBT
.
print
(
P2
,
DEC
);
SerialBT
.
print
(
P3
,
DEC
);
SerialBT
.
println
(
P4
,
DEC
);
myDFPlayer
.
play
(
3
);
startTimer
=
0
;
state
=
4
;
}
if
(
startTimer
==
1
&&
desbloqueo
==
1
){
SerialBT
.
println
(
"Se ha adivinado la contraseña :"
);
myDFPlayer
.
play
(
2
);
SerialBT
.
print
(
P1
,
DEC
);
SerialBT
.
print
(
P2
,
DEC
);
SerialBT
.
print
(
P3
,
DEC
);
SerialBT
.
println
(
P4
,
DEC
);
startTimer
=
0
;
state
=
3
;
}
break
;
case
3
:
//Suponemos que la pista 2 dura 10 segundos
delay
(
pista2
*
1000
);
SerialBT
.
println
(
"Se ha reproducido la siguiente instrucción"
);
startTimer
=
0
;
state
=
1
;
break
;
case
4
:
//Suponemos que la pista 2 dura 10 segundos
delay
(
pista3
*
1000
);
SerialBT
.
println
(
"fallo"
);
startTimer
=
0
;
state
=
1
;
break
;
default:
break
;
}
}
void
detectsMovement
()
{
Serial
.
println
(
"Motion detected"
);
//linea para activar mp3
startTimer
=
1
;
//comienza cuenta atras, debo decidir de cuanto la hago
lastTrigger
=
millis
();
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment