-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcalibrate.coffee
More file actions
39 lines (32 loc) · 1008 Bytes
/
calibrate.coffee
File metadata and controls
39 lines (32 loc) · 1008 Bytes
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
PORT = 33333
HOST = process.env.SERVER || '192.168.133.100'
dgram = require('dgram')
readline = require('readline')
rl = readline.createInterface
input: process.stdin
output: process.stdout
client = dgram.createSocket('udp4')
light = (n) =>
message = new Buffer("#{n},214,29,125,0")
client.send message, 0, message.length, PORT, HOST, (err, bytes) ->
throw err if err
# console.log "UDP message sent to #{HOST}:#{PORT} => #{message.toString()}"
light_off = (n) =>
message = new Buffer("#{n},0,0,0,0")
client.send message, 0, message.length, PORT, HOST, (err, bytes) ->
throw err if err
# console.log "UDP message sent to #{HOST}:#{PORT} => #{message.toString()}"
i = 0
ask = ->
rl.question "Next? ", (answer) ->
if answer is 'no'
console.log("Thank you for your valuable feedback:", answer)
client.close()
rl.close()
process.exit()
console.log("Turning on LED: #{i}")
light(i)
light_off(i - 1)
i++
setTimeout ask, 10
ask()