Skip to content

Commit 8b1fe25

Browse files
committed
docs: add example
1 parent ec4ce69 commit 8b1fe25

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

example.js

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// We must run this as root since we are accessing hardware directly.
2+
// Furthermore just one instance of this driver is allowed per Pi concurrently.
3+
4+
// Load and configure the drivers:
5+
const DMX = require( '.' )( {
6+
// Any free GPIO can be used:
7+
pinTx: 22, // Data pin
8+
pinEn: 27, // Enable ping
9+
// The signal levels can be inverted if neccessary:
10+
invTx: true, // Data pin
11+
invEn: true // Enable pin
12+
} );
13+
14+
function fadeDMX( ch3 ) {
15+
16+
// Stop when channel 3 reached 255
17+
if( ch3 > 255 ) return;
18+
19+
// Create buffer that will be transmitted: Ch 1, 2, 4, 5 are static and Ch 3 is faded
20+
let data = Buffer.from( [ 0, 128, ch3, 0, 0] );
21+
22+
// DMX.transmit( data ) returns a promise that is fulfilled if the data has been transmitted
23+
return DMX.transmit( data ).then( () => fadeDMX( ++ch3 ) );
24+
25+
}
26+
27+
// Start fading and shutdown the driver when fading has been finished
28+
fadeDMX( 0 ).then( () => DMX.close() ).catch( console.error );
29+

0 commit comments

Comments
 (0)