⚲
Projet
Général
Profil
Connexion
S'enregistrer
Accueil
Projets
Aide
Recherche
:
Polytech Ge Sous Traitance
Tous les projets
Polytech Projets Ge
»
Polytech Ge Sous Traitance
Aperçu
Activité
Roadmap
Demandes
Gantt
Calendrier
Annonces
Documents
Wiki
Fichiers
Dépôt
Télécharger (1,31 ko)
Feature #13603
» arduino_code_13603 (1).ino
Anonyme, 26/11/2021 14:19
#include
<SoftwareSerial.h>
enum
Switch
{
opened
=
0
,
closed
=
1
};
enum
Switch
state
;
int
Vval
;
// value diffrence in voltage
unsigned
int
StartTime
;
unsigned
int
CurrentTime
;
unsigned
int
ElapsedTime
;
unsigned
char
flaginit
=
0
;
SoftwareSerial
hc06
(
10
,
11
);
int
readport
(
uint8_t
val1
,
uint8_t
val2
)
{
int
returnVal
=
analogRead
(
val1
)
-
analogRead
(
val2
);
if
(
abs
(
returnVal
)
<
9
)
return
0
;
else
return
returnVal
;
}
void
setup
()
{
hc06
.
begin
(
9600
);
//Serial.begin(9600);
Vval
=
readport
(
A1
,
A0
);
//case where I start with an open circuit
if
(
!
Vval
)
state
=
opened
;
else
state
=
closed
;
}
void
loop
()
{
Vval
=
readport
(
A0
,
A1
);
if
(
state
==
closed
&&
!
flaginit
)
{
hc06
.
println
(
"you must start with an open circuit"
);
delay
(
50
);
exit
(
0
);
}
flaginit
=
1
;
do
//start counter when the circuit is closed for the first time
{
Vval
=
readport
(
A0
,
A1
);
delay
(
7
);
}
while
(
!
Vval
);
StartTime
=
millis
();
do
//stop counter when the circuit reclosed
{
Vval
=
readport
(
A0
,
A1
);
delay
(
7
);
}
while
(
Vval
);
CurrentTime
=
millis
();
//Print result to smartphone
ElapsedTime
=
CurrentTime
-
StartTime
-
14
;
hc06
.
println
(
"Elapsed time is: "
);
hc06
.
println
(
ElapsedTime
);
//Send message to smartphone
}
(1-1/1)
Chargement...