Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Sebastián Collado Montañez
/
proyecto-micro
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
65f5c994
authored
Dec 17, 2017
by
Sebastián Collado Montañez
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
ultrasonidos test
parent
cc6f2587
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
0 deletions
webserver.js
webserver.js
View file @
65f5c994
...
...
@@ -18,16 +18,45 @@ var RED = new Gpio(4, { mode: Gpio.OUTPUT });
var
GREEN
=
new
Gpio
(
17
,
{
mode
:
Gpio
.
OUTPUT
});
var
BLUE
=
new
Gpio
(
27
,
{
mode
:
Gpio
.
OUTPUT
});
var
motor
=
new
Gpio
(
13
,
{
mode
:
Gpio
.
OUTPUT
});
var
trigger
=
new
Gpio
(
23
,
{
mode
:
Gpio
.
OUTPUT
}),
var
echo
=
new
Gpio
(
24
,
{
mode
:
Gpio
.
INPUT
,
alert
:
true
});
var
MICROSECDONDS_PER_CM
=
1
e6
/
34321
;
var
pulseWidth
=
1850
;
motor
.
servoWrite
(
pulseWidth
);
RED
.
pwmWrite
(
255
);
GREEN
.
pwmWrite
(
0
);
BLUE
.
pwmWrite
(
0
);
trigger
.
digitalWrite
(
0
);
// Ultrasonidos
(
function
()
{
var
startTick
;
echo
.
on
(
'alert'
,
function
(
level
,
tick
)
{
var
endTick
,
diff
;
if
(
level
==
1
)
{
startTick
=
tick
;
}
else
{
endTick
=
tick
;
diff
=
(
endTick
>>
0
)
-
(
startTick
>>
0
);
// Unsigned 32 bit arithmetic
console
.
log
(
diff
/
2
/
MICROSECDONDS_PER_CM
);
}
});
}());
// Trigger a distance measurement once per second
setInterval
(
function
()
{
trigger
.
trigger
(
10
,
1
);
// Set trigger high for 10 microseconds
},
1000
);
// Abrir puerta
function
abrirPuerta
(){
RED
.
pwmWrite
(
0
);
GREEN
.
pwmWrite
(
255
);
var
increment
=
-
10
;
...
...
@@ -48,6 +77,7 @@ function abrirPuerta(){
// Cerrar puerta
function
cerrarPuerta
(){
GREEN
.
pwmWrite
(
0
);
RED
.
pwmWrite
(
255
);
var
increment
=
10
;
...
...
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