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
a38aa75f
authored
Dec 15, 2017
by
Sebastián Collado Montañez
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
servo test
parent
fa3d7fa4
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
34 deletions
webserver.js
webserver.js
View file @
a38aa75f
...
@@ -8,47 +8,42 @@ var Gpio = require('pigpio').Gpio;
...
@@ -8,47 +8,42 @@ var Gpio = require('pigpio').Gpio;
GPIO
GPIO
*/
*/
var
RED
=
new
Gpio
(
4
,
{
mode
:
Gpio
.
OUTPUT
});
// Inicializacion de pines
var
GREEN
=
new
Gpio
(
17
,
{
mode
:
Gpio
.
OUTPUT
});
var
RED
=
new
Gpio
(
4
,
{
mode
:
Gpio
.
OUTPUT
});
var
BLUE
=
new
Gpio
(
27
,
{
mode
:
Gpio
.
OUTPUT
});
var
GREEN
=
new
Gpio
(
17
,
{
mode
:
Gpio
.
OUTPUT
});
var
BLUE
=
new
Gpio
(
27
,
{
mode
:
Gpio
.
OUTPUT
});
// Valor de puerta cerrada 1850
var
motor
=
new
Gpio
(
13
,
{
mode
:
Gpio
.
OUTPUT
});
// Valor de puerta abierta 950
// Puerta cerrada:1850
// La amplitud de apertura es 900 (90 grados)
// Puerta abierta: 950
// Tiempo para la apertura: 10s
// Rango apertura: 900
var
motor
=
new
Gpio
(
13
,
{
mode
:
Gpio
.
OUTPUT
});
var
pulseWidth
=
1850
;
var
pulseWidth
=
1850
;
var
increment
=
-
10
;
var
increment
=
-
10
;
motor
.
servoWrite
(
pulseWidth
);
// Apertura y cierre continuo
/*setInterval(function () {
motor.servoWrite(pulseWidth);
for
(
var
i
=
0
;
i
<
90
;
i
++
){
pulseWidth += increment;
setTimeout
(
function
(){
openFunct
();},
100
);
if
(
pulseWidth
>
950
){
if (pulseWidth >= 1850) {
console
.
log
(
"Fuera de rango en apertura"
);
increment = -10;
break
;
} else if (pulseWidth <= 950) {
increment = 10;
}
}
}
function
openFunct
(){
motor
.
servoWrite
(
pulseWidth
);
pulseWidth
+=
-
10
;
}
/*var test = setInterval(function () {
}, 100);*/
motor.servoWrite(pulseWidth);
pulseWidth += increment;
// Apertura
var
apertura
=
setInterval
(
function
()
{
motor
.
servoWrite
(
pulseWidth
);
if (pulseWidth >= 1850) {
if
(
pulseWidth
>=
1850
)
{
increment = -10;
increment
=
-
10
;
} else if (pulseWidth <= 950) {
}
else
if
(
pulseWidth
<=
950
)
{
increment = 10
;
clearInterval
(
apertura
)
;
}
}
}, 100);
*/
},
100
);
// Clean LEDs
// Clean LEDs
//RED.pwmWrite(dutyCycle);
//RED.pwmWrite(dutyCycle);
...
@@ -60,7 +55,7 @@ function openFunct(){
...
@@ -60,7 +55,7 @@ function openFunct(){
WEB SERVER
WEB SERVER
*/
*/
app
.
use
(
'/public'
,
express
.
static
(
__dirname
+
'/public'
));
app
.
use
(
'/public'
,
express
.
static
(
__dirname
+
'/public'
));
app
.
get
(
'/'
,
function
(
req
,
res
)
{
app
.
get
(
'/'
,
function
(
req
,
res
)
{
res
.
sendFile
(
__dirname
+
'/views/index.html'
);
res
.
sendFile
(
__dirname
+
'/views/index.html'
);
});
});
server
.
listen
(
'8080'
);
server
.
listen
(
'8080'
);
...
@@ -72,7 +67,7 @@ server.listen('8080');
...
@@ -72,7 +67,7 @@ server.listen('8080');
var
estadoPuerta
=
0
;
//cerrada
var
estadoPuerta
=
0
;
//cerrada
io
.
sockets
.
on
(
'connection'
,
function
(
socket
)
{
// WebSocket Connection
io
.
sockets
.
on
(
'connection'
,
function
(
socket
)
{
// WebSocket Connection
console
.
log
(
"Cliente conectado"
);
console
.
log
(
"Cliente conectado"
);
...
@@ -80,7 +75,7 @@ io.sockets.on('connection', function(socket) { // WebSocket Connection
...
@@ -80,7 +75,7 @@ io.sockets.on('connection', function(socket) { // WebSocket Connection
socket
.
emit
(
"inicializacion"
,
Number
(
estadoPuerta
));
socket
.
emit
(
"inicializacion"
,
Number
(
estadoPuerta
));
//Escucha la orden del cliente
//Escucha la orden del cliente
socket
.
on
(
'emisionOrden'
,
function
(
data
)
{
//get light switch status from client
socket
.
on
(
'emisionOrden'
,
function
(
data
)
{
//get light switch status from client
var
ordenRecibida
=
data
;
var
ordenRecibida
=
data
;
...
...
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