-
Notifications
You must be signed in to change notification settings - Fork 0
/
morsify.js
82 lines (69 loc) · 2.05 KB
/
morsify.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
var m = require('./alphabet.js');
var b = require('bonescript');
var app = require('http').createServer(handler);
var io = require('socket.io').listen(app);
var fs= require('fs');
var ledPin = "P8_13";
var mString = "welcome";
var state = b.LOW;
var ps=100; // 20 en iyi değer, 100 normal değer
app.listen(9090);
b.pinMode(ledPin, b.OUTPUT);
b.digitalWrite(ledPin, state);
toggle(mString);
function handler(req,res){
fs.readFile('index.html',
function(err,data){
if(err){
res.writeHead(500);
return res.end('500.html');
}
res.writeHead(200);
res.end(data);
});
}
io.sockets.on('connection',function(socket){
socket.on('sendval',function(data){
console.log("Socket :" + socket);
console.log("Request :" + data);
toggle(data.toLowerCase());
//socket.emit('datastatus','sent');
//socket.broadcast.emit('dataupdate','ok);
});
});
function toggle(mstring) {
for(var i = 0;i<mstring.length;i++){
var letter = mstring.charAt(i);
var mors= m.getMorse(letter);
//io.sockets.socket.write(letter);
for(var j = 0; j < mors.length;j++){
console.log(letter + "["+j+"]:" +mors);
switch (mors.charAt(j)){
case "0":
b.digitalWrite(ledPin,b.HIGH);
waitabit(ps);
break;
case "1":
b.digitalWrite(ledPin,b.HIGH);
waitabit(ps*3);
break;
case "2":
waitabit(ps);
break;
default:
break;
}
//parlama araları
b.digitalWrite(ledPin,b.LOW);
waitabit(ps);
}
//harf araları
waitabit(ps*3);
b.digitalWrite(ledPin,b.LOW);
}
b.digitalWrite(ledPin, b.LOW);
}
function waitabit (bit){
var startTime = new Date().getTime();
while (new Date().getTime() < startTime + bit);
}