UNPKG

2 kBMarkdownView Raw
1#Infrared
2Driver for the ir-attx4 Tessel infrared module ([ATTX4]()).
3
4##Really Important Information
5e.g. "this isn't ready to go yet" or "here is some special way you have to use this or it won't work"
6Hopefully we don't need this section by the time we release things to the public
7
8##Installation
9```sh
10npm install ir-attx4
11```
12##Example
13```js
14var tessel = require('tessel');
15
16// Connect the IR module to port a
17var hardware = tessel.port("A");
18
19// Import library and connect to module
20var infrared = require('ir-attx4').connect(hardware);
21
22var counter = 0;
23
24// When we're connected
25infrared.on('connected', function(err) {
26 if (!err) {
27 console.log("Connected to IR!");
28
29 // Start turning tv on and off every 3 seconds
30 setInterval(powerTV, 3000);
31 }
32 else {
33 console.log("Err initializing: ", err.message );
34 }
35});
36
37// If we get data, print it out
38infrared.on('data', function(data) {
39 console.log("Received RX Data: ", data);
40});
41
42var powerTV = function() {
43
44 // Make a buffer off on/off durations (each duration is 16 bits)
45 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]);
46
47 // Send the signal at 38 kHz
48 infrared.sendRawSignal(38, powerBuffer, function(err) {
49 if (err) console.log("Unable to send signal: ", err);
50 else {
51 console.log("TV Should be powered...");
52 }
53 });
54}
55```
56
57##Methods
58
59* **`infrared`.setListening(set, callback)**
60
61* **`infrared`.sendRawSignal(frequency, signalDurations, callback)**
62
63## License
64
65MIT