-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.js
40 lines (34 loc) · 1.12 KB
/
main.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
import { TURN_DISPLAY_ON, TURN_OSCILLATOR_ON, SET_BRIGHTNESS } from './common';
const MAX_BRIGHTNESS = 15;
const MAX_BLINK_RATE = 3;
export function createMatrix(setup, format, write, address, brightness) {
const matrix = {
render: bitmap => write(address, 0, format(bitmap)),
write: (...data) => write(address, ...data)
};
setup();
matrix.write(TURN_OSCILLATOR_ON);
matrix.write(TURN_DISPLAY_ON);
setBrightness(matrix, brightness);
return matrix;
}
/**
* Set the brightness of the LEDs. A number 0 through 15.
*
* @export
* @param {Object} matrix - the configured display
* @param {number} brightness - brightness 0 through 15
*/
export function setBrightness(matrix, brightness) {
matrix.write(SET_BRIGHTNESS | brightness & MAX_BRIGHTNESS);
}
/**
* Set the blink rate of the display. A number 0 through 3.
*
* @export
* @param {Object} matrix - the configured display
* @param {number} rate - brightness 0 through 3
*/
export function setBlinkRate(matrix, rate) {
matrix.write(TURN_DISPLAY_ON | (rate & MAX_BLINK_RATE) << 1);
}