-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
99 lines (67 loc) · 2.09 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
//node v8.9.4 required
//do not use "wiring-pi", use "wiringpi-node"
//BUGS & SOLUTIONS :
//Hardware problems > edit the package who use wiring-pi and put wiringpi-node in the require instead
//Build error > change node version to v8.9.4
//Developed on Linux raspberrypi 4.14.33-v7+ #1109 SMP Tue Apr 10 17:28:38 BST 2018 armv7l GNU/Linux (8 Jessie)
/////////////////////////////////////////////// MANUAL BUTTON
var wpi = require('wiringpi-node');
// GPIO pin of the button
var configPin = 7;
wpi.setup('wpi');
wpi.pinMode(configPin, wpi.INPUT);
wpi.pullUpDnControl(configPin, wpi.PUD_UP);
wpi.wiringPiISR(configPin, wpi.INT_EDGE_BOTH, function() {
if (wpi.digitalRead(configPin)) {
console.log('Manual button pushed');
openDoor();
}
});
/////////////////////////////////////////////// SERVO CONTROL
var Gpio = require('pigpio').Gpio;
var motor = new Gpio(17, {mode: Gpio.OUTPUT});
function openDoor() {
console.log('Opening door');
motor.servoWrite(1000);
setTimeout(function() {
console.log('Closing door automatically after 3 sec (we will improve this later and close the door only after contact is made with the wall');
closeDoor();
},3000);
}
function closeDoor() {
motor.servoWrite(2000);
}
/*
setInterval(function(){
if(motor.getServoPulseWidth() == 1000) {
motor.servoWrite(2000);
}
else {
motor.servoWrite(1000);
}
}, 1000);
*/
/////////////////////////////////////////////// RFID READER
//https://pimylifeup.com/raspberry-pi-rfid-rc522/
var allowedRFID = {
'137,58,84,163':true
}
var mfrc522 = require("MFRC522-node");
var RFID = function(){
this.onStart = function(){
console.log('RFID started');
};
this.onUid = function(uid){
console.log('RFID detected: ' + uid);
if(allowedRFID[uid] != undefined && allowedRFID[uid]) {
openDoor();
}
else{
console.log('This RFID is not allowed in our database');
}
};
this.onExit = function(){
console.log('RFID exited');
};
};
mfrc522.start( new RFID() );