UNPKG

1.58 kBJavaScriptView Raw
1// Any copyright is dedicated to the Public Domain.
2// http://creativecommons.org/publicdomain/zero/1.0/
3
4var tessel = require('tessel');
5
6// Connect the IR module to port a
7var hardware = tessel.port('a');
8
9// Import library and connect to module
10var infrared = require('../index').use(hardware);
11
12// When we're connected
13infrared.on('ready', function() {
14 if (!err) {
15 console.log("Connected to IR!");
16
17 // Start turning sending a signal every three seconds
18 setInterval(sendSignal, 3000);
19 }
20 else {
21 console.log("Err initializing: ", err.message );
22 }
23});
24
25// If we get data, print it out
26infrared.on('data', function(data) {
27 console.log("Received RX Data: ", data);
28});
29
30var sendSignal = function() {
31
32 // Make a buffer off on/off durations (each duration is 16 bits)
33 var powerBuffer = new Buffer([0, 178, 255, 168, 0, 12, 255, 246, 0, 13, 255, 225, 0, 13, 255, 224, 0, 12, 255, 246, 0, 12, 255, 246, 0, 13, 255, 247, 0, 13, 255, 247, 0, 13, 255, 224, 0, 12, 255, 224, 0, 13, 255, 247, 0, 13, 255, 224, 0, 12, 255, 246, 0, 12, 255, 246, 0, 12, 255, 246, 0, 12, 255, 246, 0, 13, 255, 247, 0, 13, 255, 224, 0, 12, 255, 224, 0, 13, 255, 225, 0, 13, 255, 224, 0, 12, 255, 246, 0, 12, 255, 246, 0, 13, 255, 247, 0, 13, 255, 247, 0, 13, 255, 246, 0, 12, 255, 246, 0, 12, 255, 246, 0, 12, 255, 246, 0, 12, 255, 224, 0, 13, 255, 224, 0, 12, 255, 224, 0, 12, 255, 224, 0, 12]);
34
35 // Send the signal at 38 kHz
36 infrared.sendRawSignal(38, powerBuffer, function(err) {
37 if (err) console.log("Unable to send signal: ", err);
38 else {
39 console.log("Signal sent!");
40 }
41 });
42};