periph 1.0.1 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +54 -12
- package/examples/accelerometer/adxl345/complete.js +52 -0
- package/examples/accelerometer/adxl345/demo.js +34 -0
- package/examples/accelerometer/adxl345/minimal.js +18 -0
- package/examples/accelerometer/adxl362/complete.js +57 -0
- package/examples/accelerometer/adxl362/demo.js +51 -0
- package/examples/accelerometer/adxl362/minimal.js +21 -0
- package/examples/adc_dac/ad7705/complete.js +32 -0
- package/examples/adc_dac/ad7705/demo.js +42 -0
- package/examples/adc_dac/ad7705/minimal.js +16 -0
- package/examples/adc_dac/ad7706/complete.js +35 -0
- package/examples/adc_dac/ad7706/demo.js +44 -0
- package/examples/adc_dac/ad7706/minimal.js +16 -0
- package/examples/adc_dac/hx710a/complete.js +45 -0
- package/examples/adc_dac/hx710a/demo.js +52 -0
- package/examples/adc_dac/hx710a/minimal.js +16 -0
- package/examples/adc_dac/hx710b/complete.js +45 -0
- package/examples/adc_dac/hx710b/demo.js +64 -0
- package/examples/adc_dac/hx710b/minimal.js +16 -0
- package/examples/adc_dac/hx711/complete.js +42 -0
- package/examples/adc_dac/hx711/demo.js +35 -0
- package/examples/adc_dac/hx711/minimal.js +16 -0
- package/examples/adc_dac/mcp4725/complete.js +19 -17
- package/examples/adc_dac/mcp4725/demo.js +5 -5
- package/examples/adc_dac/mcp4725/minimal.js +8 -6
- package/examples/adc_dac/mcp4728/complete.js +43 -0
- package/examples/adc_dac/mcp4728/demo.js +41 -0
- package/examples/adc_dac/mcp4728/minimal.js +13 -0
- package/examples/adc_dac/pcf8591/complete.js +41 -0
- package/examples/adc_dac/pcf8591/demo.js +39 -0
- package/examples/adc_dac/pcf8591/minimal.js +19 -0
- package/examples/comms/mcp2515/complete.js +75 -0
- package/examples/comms/mcp2515/demo.js +66 -0
- package/examples/comms/mcp2515/minimal.js +27 -0
- package/examples/comms/rda5807m/complete.js +55 -0
- package/examples/comms/rda5807m/demo.js +68 -0
- package/examples/comms/rda5807m/minimal.js +15 -0
- package/examples/comms/rfm9x/complete.js +50 -0
- package/examples/comms/rfm9x/demo.js +55 -0
- package/examples/comms/rfm9x/minimal.js +20 -0
- package/examples/display/pcf8576/complete.js +35 -0
- package/examples/display/pcf8576/demo.js +48 -0
- package/examples/display/pcf8576/minimal.js +20 -0
- package/examples/environmental/aht21/complete.js +32 -0
- package/examples/environmental/aht21/demo.js +46 -0
- package/examples/environmental/aht21/minimal.js +12 -0
- package/examples/environmental/bme280/complete.js +37 -0
- package/examples/environmental/bme280/demo.js +67 -0
- package/examples/environmental/bme280/minimal.js +20 -0
- package/examples/environmental/bme680/complete.js +40 -0
- package/examples/environmental/bme680/demo.js +54 -0
- package/examples/environmental/bme680/minimal.js +21 -0
- package/examples/gas/ens160/complete.js +54 -0
- package/examples/gas/ens160/demo.js +54 -0
- package/examples/gas/ens160/minimal.js +29 -0
- package/examples/gnss/neo6/complete.js +49 -0
- package/examples/gnss/neo6/demo.js +54 -0
- package/examples/gnss/neo6/minimal.js +30 -0
- package/examples/gyroscope/l3g4200d/complete.js +56 -0
- package/examples/gyroscope/l3g4200d/demo.js +49 -0
- package/examples/gyroscope/l3g4200d/minimal.js +19 -0
- package/examples/gyroscope/l3gd20h/complete.js +42 -0
- package/examples/gyroscope/l3gd20h/demo.js +29 -0
- package/examples/gyroscope/l3gd20h/minimal.js +13 -0
- package/examples/humidity/dht11/complete.js +22 -0
- package/examples/humidity/dht11/demo.js +38 -0
- package/examples/humidity/dht11/minimal.js +18 -0
- package/examples/imu/mpu6050/complete.js +58 -0
- package/examples/imu/mpu6050/demo.js +37 -0
- package/examples/imu/mpu6050/minimal.js +14 -0
- package/examples/imu/mpu9250/complete.js +65 -0
- package/examples/imu/mpu9250/demo.js +53 -0
- package/examples/imu/mpu9250/minimal.js +21 -0
- package/examples/imu/mpu9255/complete.js +73 -0
- package/examples/imu/mpu9255/demo.js +73 -0
- package/examples/imu/mpu9255/minimal.js +21 -0
- package/examples/io_expander/mcp23017/complete.js +70 -77
- package/examples/io_expander/mcp23017/demo.js +37 -33
- package/examples/io_expander/mcp23017/minimal.js +15 -11
- package/examples/io_expander/pcf8574/complete.js +60 -65
- package/examples/io_expander/pcf8574/demo.js +30 -25
- package/examples/io_expander/pcf8574/minimal.js +15 -11
- package/examples/io_expander/pcf8575/complete.js +24 -20
- package/examples/io_expander/pcf8575/demo.js +27 -23
- package/examples/io_expander/pcf8575/minimal.js +16 -12
- package/examples/io_expander/tpic6b595/complete.js +57 -0
- package/examples/io_expander/tpic6b595/demo.js +75 -0
- package/examples/io_expander/tpic6b595/minimal.js +26 -0
- package/examples/led/apa102/complete.js +72 -0
- package/examples/led/apa102/demo.js +92 -0
- package/examples/led/apa102/minimal.js +21 -0
- package/examples/led/sk6812rgbw/complete.js +42 -40
- package/examples/led/sk6812rgbw/demo.js +16 -16
- package/examples/led/sk6812rgbw/minimal.js +15 -17
- package/examples/led/ws2812b/complete.js +40 -38
- package/examples/led/ws2812b/demo.js +16 -16
- package/examples/led/ws2812b/minimal.js +13 -14
- package/examples/led/ws2814/complete.js +71 -0
- package/examples/led/ws2814/demo.js +82 -0
- package/examples/led/ws2814/minimal.js +23 -0
- package/examples/light/apds-9930/complete.js +46 -0
- package/examples/light/apds-9930/demo.js +31 -0
- package/examples/light/apds-9930/minimal.js +20 -0
- package/examples/light/apds9960/complete.js +64 -0
- package/examples/light/apds9960/demo.js +34 -0
- package/examples/light/apds9960/minimal.js +12 -0
- package/examples/magnetometer/as5600/complete.js +31 -29
- package/examples/magnetometer/as5600/demo.js +35 -33
- package/examples/magnetometer/as5600/minimal.js +7 -7
- package/examples/magnetometer/hmc5883l/complete.js +47 -0
- package/examples/magnetometer/hmc5883l/demo.js +50 -0
- package/examples/magnetometer/hmc5883l/minimal.js +15 -0
- package/examples/memory/24aa02uid/complete.js +42 -0
- package/examples/memory/24aa02uid/demo.js +42 -0
- package/examples/memory/24aa02uid/minimal.js +12 -0
- package/examples/other/mpr121/complete.js +50 -0
- package/examples/other/mpr121/demo.js +30 -0
- package/examples/other/mpr121/minimal.js +17 -0
- package/examples/power/ade7953/complete.js +44 -0
- package/examples/power/ade7953/demo.js +28 -0
- package/examples/power/ade7953/minimal.js +15 -0
- package/examples/power/ina219/complete.js +20 -18
- package/examples/power/ina219/demo.js +15 -13
- package/examples/power/ina219/minimal.js +8 -8
- package/examples/power/ina226/complete.js +24 -22
- package/examples/power/ina226/demo.js +22 -20
- package/examples/power/ina226/minimal.js +5 -5
- package/examples/power/ina3221/complete.js +51 -49
- package/examples/power/ina3221/demo.js +13 -13
- package/examples/power/ina3221/minimal.js +8 -8
- package/examples/pressure/bmp085/complete.js +29 -0
- package/examples/pressure/bmp085/demo.js +34 -0
- package/examples/pressure/bmp085/minimal.js +19 -0
- package/examples/pressure/bmp180/complete.js +20 -17
- package/examples/pressure/bmp180/demo.js +24 -22
- package/examples/pressure/bmp180/minimal.js +13 -11
- package/examples/pressure/bmp280/complete.js +29 -22
- package/examples/pressure/bmp280/demo.js +42 -23
- package/examples/pressure/bmp280/minimal.js +13 -11
- package/examples/pressure/bmp384/complete.js +29 -0
- package/examples/pressure/bmp384/demo.js +40 -0
- package/examples/pressure/bmp384/minimal.js +18 -0
- package/examples/pressure/bmp581/complete.js +34 -0
- package/examples/pressure/bmp581/demo.js +56 -0
- package/examples/pressure/bmp581/minimal.js +19 -0
- package/examples/pressure/lps22df/complete.js +50 -0
- package/examples/pressure/lps22df/demo.js +41 -0
- package/examples/pressure/lps22df/minimal.js +19 -0
- package/examples/pressure/lps28dfw/complete.js +37 -0
- package/examples/pressure/lps28dfw/demo.js +33 -0
- package/examples/pressure/lps28dfw/minimal.js +19 -0
- package/examples/pressure/lps33hw/complete.js +43 -0
- package/examples/pressure/lps33hw/demo.js +43 -0
- package/examples/pressure/lps33hw/minimal.js +19 -0
- package/examples/rfid/mfrc522/complete.js +44 -0
- package/examples/rfid/mfrc522/demo.js +70 -0
- package/examples/rfid/mfrc522/minimal.js +17 -0
- package/package.json +5 -1
- package/src/chips/accelerometer/adxl345.js +482 -0
- package/src/chips/accelerometer/adxl362.js +594 -0
- package/src/chips/adc_dac/ad7705.js +345 -0
- package/src/chips/adc_dac/ad7706.js +331 -0
- package/src/chips/adc_dac/hx710a.js +184 -0
- package/src/chips/adc_dac/hx710b.js +186 -0
- package/src/chips/adc_dac/hx711.js +165 -0
- package/src/chips/adc_dac/mcp4725.js +48 -40
- package/src/chips/adc_dac/mcp4728.js +297 -0
- package/src/chips/adc_dac/pcf8591.js +196 -0
- package/src/chips/comms/mcp2515.js +659 -0
- package/src/chips/comms/rda5807m.js +393 -0
- package/src/chips/comms/rfm9x.js +590 -0
- package/src/chips/display/pcf8576.js +232 -0
- package/src/chips/environmental/aht21.js +185 -0
- package/src/chips/environmental/bme280.js +385 -0
- package/src/chips/environmental/bme680.js +512 -0
- package/src/chips/gas/ens160.js +298 -0
- package/src/chips/gnss/neo6.js +438 -0
- package/src/chips/gyroscope/l3g4200d.js +366 -0
- package/src/chips/gyroscope/l3gd20h.js +314 -0
- package/src/chips/humidity/dht11.js +135 -0
- package/src/chips/imu/mpu6050.js +289 -0
- package/src/chips/imu/mpu9250.js +394 -0
- package/src/chips/imu/mpu9255.js +447 -0
- package/src/chips/io_expander/mcp23017.js +240 -157
- package/src/chips/io_expander/pcf8574.js +149 -124
- package/src/chips/io_expander/pcf8575.js +164 -135
- package/src/chips/io_expander/tpic6b595.js +242 -0
- package/src/chips/led/_NeoPixelRGBBase.js +204 -0
- package/src/chips/led/_NeoPixelRGBWBase.js +218 -0
- package/src/chips/led/apa102.js +236 -0
- package/src/chips/led/sk6812rgbw.js +15 -149
- package/src/chips/led/ws2812b.js +14 -139
- package/src/chips/led/ws2814.js +49 -0
- package/src/chips/light/apds-9930.js +342 -0
- package/src/chips/light/apds9960.js +499 -0
- package/src/chips/magnetometer/as5600.js +102 -82
- package/src/chips/magnetometer/hmc5883l.js +222 -0
- package/src/chips/memory/_24aa02uid.js +182 -0
- package/src/chips/other/mpr121.js +375 -0
- package/src/chips/power/ade7953.js +427 -0
- package/src/chips/power/ina219.js +45 -40
- package/src/chips/power/ina226.js +50 -45
- package/src/chips/power/ina3221.js +95 -76
- package/src/chips/pressure/bmp085.js +251 -0
- package/src/chips/pressure/bmp180.js +54 -37
- package/src/chips/pressure/bmp280.js +188 -206
- package/src/chips/pressure/bmp384.js +410 -0
- package/src/chips/pressure/bmp581.js +489 -0
- package/src/chips/pressure/lps22df.js +341 -0
- package/src/chips/pressure/lps28dfw.js +314 -0
- package/src/chips/pressure/lps33hw.js +255 -0
- package/src/chips/rfid/mfrc522.js +674 -0
- package/src/connection/connection.js +111 -0
- package/src/connection/dhtxx.js +138 -0
- package/src/connection/dhtxx_mock.js +39 -0
- package/src/connection/hx711.js +132 -0
- package/src/connection/hx711_mock.js +52 -0
- package/src/{transport → connection}/i2c.js +13 -9
- package/src/connection/i2c_mock.js +91 -0
- package/src/connection/input_pin.js +156 -0
- package/src/connection/neo6_mock.js +45 -0
- package/src/{transport → connection}/neopixel.js +23 -4
- package/src/connection/output_pin.js +41 -0
- package/src/connection/sipo.js +159 -0
- package/src/{transport → connection}/smbus.js +14 -10
- package/src/{transport → connection}/spi.js +12 -8
- package/src/connection/spi_mock.js +151 -0
- package/src/{transport → connection}/uart.js +33 -26
- package/examples/display/.gitkeep +0 -0
- package/examples/environmental/.gitkeep +0 -0
- package/examples/gnss/.gitkeep +0 -0
- package/examples/humidity/.gitkeep +0 -0
- package/examples/imu/.gitkeep +0 -0
- package/examples/light/.gitkeep +0 -0
- package/examples/pressure/.gitkeep +0 -0
- package/src/chips/display/.gitkeep +0 -0
- package/src/chips/environmental/.gitkeep +0 -0
- package/src/chips/gnss/.gitkeep +0 -0
- package/src/chips/imu/.gitkeep +0 -0
- package/src/chips/light/.gitkeep +0 -0
- package/src/chips/pressure/.gitkeep +0 -0
|
@@ -1,69 +1,71 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const {
|
|
3
|
+
const { NeoPixelConnection } = require('../../../src/connection/neopixel');
|
|
4
4
|
const { SK6812RGBWFull } = require('../../../src/chips/led/sk6812rgbw');
|
|
5
5
|
|
|
6
6
|
const SPI_BUS = parseInt(process.env.SPI_BUS || '0', 10);
|
|
7
7
|
const SPI_DEVICE = parseInt(process.env.SPI_DEVICE || '0', 10);
|
|
8
8
|
|
|
9
|
-
const
|
|
10
|
-
const strip = new SK6812RGBWFull(
|
|
9
|
+
const connection = new NeoPixelConnection(SPI_BUS, SPI_DEVICE); // Create NeoPixel connection, (busNumber, deviceNumber)
|
|
10
|
+
const strip = new SK6812RGBWFull(connection, 8); // Create SK6812RGBW full driver, (connection, n=8 pixels)
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
(async () => {
|
|
13
|
+
// fill — set all pixels and send immediately
|
|
14
|
+
await strip.fill(255, 0, 0); // Fill all pixels with one colour, (r=0–255, g=0–255, b=0–255, w=0–255) → void
|
|
15
|
+
// stores GRBW in buffer and calls connection.write()
|
|
15
16
|
|
|
16
|
-
// fill with white channel
|
|
17
|
-
strip.fill(0, 0, 0, 255);
|
|
17
|
+
// fill with white channel
|
|
18
|
+
await strip.fill(0, 0, 0, 255); // Fill all pixels using W channel, (r=0–255, g=0–255, b=0–255, w=0–255) → void
|
|
18
19
|
// w=255 activates dedicated white LED element; RGB channels stay dark
|
|
19
20
|
|
|
20
|
-
// set individual pixels then show
|
|
21
|
-
strip.set_pixel(0, 255, 0, 0);
|
|
21
|
+
// set individual pixels then show
|
|
22
|
+
strip.set_pixel(0, 255, 0, 0); // Set pixel 0 in buffer (no send), (index=0–n-1, r=0–255, g=0–255, b=0–255, w=0–255) → void
|
|
22
23
|
// writes G,R,B,W bytes into internal buffer at position index*4
|
|
23
|
-
strip.set_pixel(1, 0, 255, 0);
|
|
24
|
+
strip.set_pixel(1, 0, 255, 0); // Set pixel 1 in buffer (no send), (index=0–n-1, r=0–255, g=0–255, b=0–255, w=0–255) → void
|
|
24
25
|
// writes G,R,B,W bytes into internal buffer at position index*4
|
|
25
|
-
strip.set_pixel(2, 0, 0, 255);
|
|
26
|
+
strip.set_pixel(2, 0, 0, 255); // Set pixel 2 in buffer (no send), (index=0–n-1, r=0–255, g=0–255, b=0–255, w=0–255) → void
|
|
26
27
|
// writes G,R,B,W bytes into internal buffer at position index*4
|
|
27
|
-
strip.set_pixel(3, 0, 0, 0, 255);
|
|
28
|
+
strip.set_pixel(3, 0, 0, 0, 255); // Set pixel 3 to white in buffer (no send), (index=0–n-1, r=0–255, g=0–255, b=0–255, w=0–255) → void
|
|
28
29
|
// w=255 lights the dedicated white element; RGB remain off
|
|
29
|
-
strip.show();
|
|
30
|
-
// applies brightness scaling then calls
|
|
30
|
+
await strip.show(); // Transmit buffer to strip, () → void
|
|
31
|
+
// applies brightness scaling then calls connection.write()
|
|
31
32
|
|
|
32
|
-
// set_pixels — write multiple pixels at once
|
|
33
|
-
strip.set_pixels([[255,0,0,0],[0,255,0,0],[0,0,255,0],
|
|
34
|
-
|
|
33
|
+
// set_pixels — write multiple pixels at once
|
|
34
|
+
strip.set_pixels([[255,0,0,0],[0,255,0,0],[0,0,255,0], // Set pixels from array of [r,g,b,w], (colors=Array<[r,g,b,w?]>) → void
|
|
35
|
+
[0,0,0,255],[255,200,150,255]]);
|
|
35
36
|
// handles 3- or 4-element tuples; writes entries sequentially from pixel 0
|
|
36
|
-
strip.show();
|
|
37
|
-
// applies brightness scaling then calls
|
|
37
|
+
await strip.show(); // Transmit buffer to strip, () → void
|
|
38
|
+
// applies brightness scaling then calls connection.write()
|
|
38
39
|
|
|
39
|
-
// brightness — global scale applied at show() time
|
|
40
|
-
strip.brightness = 64;
|
|
40
|
+
// brightness — global scale applied at show() time
|
|
41
|
+
strip.brightness = 64; // Set global brightness, (value=0–255)
|
|
41
42
|
// stored value is scaled: sent = stored * brightness / 255
|
|
42
|
-
strip.show();
|
|
43
|
-
// applies brightness scaling then calls
|
|
44
|
-
strip.brightness = 255;
|
|
43
|
+
await strip.show(); // Transmit buffer to strip, () → void
|
|
44
|
+
// applies brightness scaling then calls connection.write()
|
|
45
|
+
strip.brightness = 255; // Set global brightness, (value=0–255)
|
|
45
46
|
// stored value is scaled: sent = stored * brightness / 255
|
|
46
47
|
|
|
47
|
-
// fill_hsv — fill all pixels from HSV colour (white=0)
|
|
48
|
-
strip.fill_hsv(0.0, 1.0, 1.0);
|
|
48
|
+
// fill_hsv — fill all pixels from HSV colour (white=0)
|
|
49
|
+
await strip.fill_hsv(0.0, 1.0, 1.0); // Fill all pixels with HSV colour and send, (h=0.0–1.0, s=0.0–1.0, v=0.0–1.0) → void
|
|
49
50
|
// converts HSV to RGB (w=0) then calls fill(); hue 0.0 = red
|
|
50
|
-
strip.fill_hsv(0.333, 1.0, 1.0);
|
|
51
|
+
await strip.fill_hsv(0.333, 1.0, 1.0); // Fill all pixels with HSV colour and send, (h=0.0–1.0, s=0.0–1.0, v=0.0–1.0) → void
|
|
51
52
|
// converts HSV to RGB (w=0) then calls fill(); hue 0.333 = green
|
|
52
|
-
strip.fill_hsv(0.667, 1.0, 1.0);
|
|
53
|
+
await strip.fill_hsv(0.667, 1.0, 1.0); // Fill all pixels with HSV colour and send, (h=0.0–1.0, s=0.0–1.0, v=0.0–1.0) → void
|
|
53
54
|
// converts HSV to RGB (w=0) then calls fill(); hue 0.667 = blue
|
|
54
55
|
|
|
55
|
-
// rotate — shift pixel buffer left, then show
|
|
56
|
-
strip.set_pixels([[255,0,0,0], ...Array(7).fill([0,0,0,0])]); // Set pixels from array of [r,g,b,w], (colors=Array<[r,g,b,w?]>) → void
|
|
56
|
+
// rotate — shift pixel buffer left, then show
|
|
57
|
+
strip.set_pixels([[255,0,0,0], ...Array(7).fill([0,0,0,0])]); // Set pixels from array of [r,g,b,w], (colors=Array<[r,g,b,w?]>) → void
|
|
57
58
|
// handles 3- or 4-element tuples; writes entries sequentially from pixel 0
|
|
58
|
-
strip.show();
|
|
59
|
-
// applies brightness scaling then calls
|
|
60
|
-
for (let i = 0; i < 7; i++) {
|
|
61
|
-
|
|
59
|
+
await strip.show(); // Transmit buffer to strip, () → void
|
|
60
|
+
// applies brightness scaling then calls connection.write()
|
|
61
|
+
for (let i = 0; i < 7; i++) {
|
|
62
|
+
strip.rotate(1); // Rotate pixel buffer left, (steps=1) → void
|
|
62
63
|
// shifts buffer by steps pixel positions; wraps around; does not send
|
|
63
|
-
|
|
64
|
-
// applies brightness scaling then calls
|
|
65
|
-
}
|
|
64
|
+
await strip.show(); // Transmit buffer to strip, () → void
|
|
65
|
+
// applies brightness scaling then calls connection.write()
|
|
66
|
+
}
|
|
66
67
|
|
|
67
|
-
strip.off();
|
|
68
|
+
await strip.off(); // Turn off all pixels, () → void
|
|
68
69
|
// equivalent to fill(0, 0, 0, 0)
|
|
69
|
-
|
|
70
|
+
await connection.close();
|
|
71
|
+
})();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const {
|
|
3
|
+
const { NeoPixelConnection } = require('../../../src/connection/neopixel');
|
|
4
4
|
const { SK6812RGBWFull } = require('../../../src/chips/led/sk6812rgbw');
|
|
5
5
|
|
|
6
6
|
const SPI_BUS = parseInt(process.env.SPI_BUS || '0', 10);
|
|
@@ -12,8 +12,8 @@ const RAINBOW_MS = 10000;
|
|
|
12
12
|
const WARM_MS = 2000;
|
|
13
13
|
const WARM_HALF = 100;
|
|
14
14
|
|
|
15
|
-
const
|
|
16
|
-
const strip = new SK6812RGBWFull(
|
|
15
|
+
const connection = new NeoPixelConnection(SPI_BUS, SPI_DEVICE); // Create NeoPixel connection, (busNumber, deviceNumber)
|
|
16
|
+
const strip = new SK6812RGBWFull(connection, N_PIXELS); // Create SK6812RGBW full driver, (connection, n=N_PIXELS pixels)
|
|
17
17
|
strip.brightness = 180; // Set global brightness, (value=0–255)
|
|
18
18
|
|
|
19
19
|
const { _hsvToRgb } = require('../../../src/chips/led/_color');
|
|
@@ -24,13 +24,13 @@ const { _hsvToRgb } = require('../../../src/chips/led/_color');
|
|
|
24
24
|
let hueOffset = 0;
|
|
25
25
|
let lastPrint = Date.now();
|
|
26
26
|
|
|
27
|
-
function rainbowFrame() {
|
|
27
|
+
async function rainbowFrame() {
|
|
28
28
|
for (let i = 0; i < N_PIXELS; i++) {
|
|
29
29
|
const h = (hueOffset + i / N_PIXELS) % 1.0;
|
|
30
30
|
const [r, g, b] = _hsvToRgb(h, 1.0, 1.0);
|
|
31
31
|
strip.set_pixel(i, r, g, b, 0); // Set pixel i to rainbow hue (w=0), (index=0–n-1, r=0–255, g=0–255, b=0–255, w=0–255) → void
|
|
32
32
|
}
|
|
33
|
-
strip.show();
|
|
33
|
+
await strip.show(); // Transmit buffer to strip, () → void
|
|
34
34
|
hueOffset = (hueOffset + 1.0 / (N_PIXELS * 2)) % 1.0;
|
|
35
35
|
const now = Date.now();
|
|
36
36
|
if (now - lastPrint >= 1000) {
|
|
@@ -40,8 +40,8 @@ function rainbowFrame() {
|
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
const rainbowStart = Date.now();
|
|
43
|
-
const rainbowTimer = setInterval(() => {
|
|
44
|
-
rainbowFrame();
|
|
43
|
+
const rainbowTimer = setInterval(async () => {
|
|
44
|
+
await rainbowFrame();
|
|
45
45
|
if (Date.now() - rainbowStart >= RAINBOW_MS) {
|
|
46
46
|
clearInterval(rainbowTimer);
|
|
47
47
|
startWarm();
|
|
@@ -52,14 +52,14 @@ const rainbowTimer = setInterval(() => {
|
|
|
52
52
|
// All four channels active (r=255, g=200, b=150, w=255) gives a warm,
|
|
53
53
|
// high-CRI white; toggling at 5 Hz for 2 seconds draws the eye to the
|
|
54
54
|
// difference between mixed-RGB white and the native W element. ---
|
|
55
|
-
function startWarm() {
|
|
55
|
+
async function startWarm() {
|
|
56
56
|
strip.brightness = 255; // Set global brightness, (value=0–255)
|
|
57
|
-
strip.fill(255, 200, 150, 255);
|
|
57
|
+
await strip.fill(255, 200, 150, 255); // Pre-load warm white (RGB+W) into buffer, (r=0–255, g=0–255, b=0–255, w=0–255) → void
|
|
58
58
|
let state = true;
|
|
59
59
|
const warmStart = Date.now();
|
|
60
|
-
const warmTimer = setInterval(() => {
|
|
60
|
+
const warmTimer = setInterval(async () => {
|
|
61
61
|
strip.brightness = state ? 255 : 0; // Toggle brightness on/off, (value=0–255)
|
|
62
|
-
strip.show();
|
|
62
|
+
await strip.show(); // Transmit buffer to strip, () → void
|
|
63
63
|
state = !state;
|
|
64
64
|
if (Date.now() - warmStart >= WARM_MS) {
|
|
65
65
|
clearInterval(warmTimer);
|
|
@@ -73,13 +73,13 @@ function startRainbowContinuous() {
|
|
|
73
73
|
strip.brightness = 180; // Set global brightness, (value=0–255)
|
|
74
74
|
hueOffset = 0;
|
|
75
75
|
lastPrint = Date.now();
|
|
76
|
-
setInterval(() => {
|
|
77
|
-
rainbowFrame();
|
|
76
|
+
setInterval(async () => {
|
|
77
|
+
await rainbowFrame();
|
|
78
78
|
}, FRAME_MS);
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
-
process.on('SIGINT', () => {
|
|
82
|
-
strip.off();
|
|
83
|
-
|
|
81
|
+
process.on('SIGINT', async () => {
|
|
82
|
+
await strip.off();
|
|
83
|
+
await connection.close();
|
|
84
84
|
process.exit(0);
|
|
85
85
|
});
|
|
@@ -1,25 +1,23 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const {
|
|
3
|
+
const { NeoPixelConnection } = require('../../../src/connection/neopixel');
|
|
4
4
|
const { SK6812RGBWMinimal } = require('../../../src/chips/led/sk6812rgbw');
|
|
5
5
|
|
|
6
6
|
const SPI_BUS = parseInt(process.env.SPI_BUS || '0', 10);
|
|
7
7
|
const SPI_DEVICE = parseInt(process.env.SPI_DEVICE || '0', 10);
|
|
8
8
|
|
|
9
|
-
const
|
|
10
|
-
const strip = new SK6812RGBWMinimal(
|
|
9
|
+
const connection = new NeoPixelConnection(SPI_BUS, SPI_DEVICE); // Create NeoPixel connection, (busNumber, deviceNumber)
|
|
10
|
+
const strip = new SK6812RGBWMinimal(connection, 30); // Create SK6812RGBW driver, (connection, n=30 pixels)
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}, 1000);
|
|
25
|
-
}, 1000);
|
|
12
|
+
(async () => {
|
|
13
|
+
await strip.fill(255, 0, 0); // Fill all pixels red, (r=0–255, g=0–255, b=0–255, w=0–255) → void
|
|
14
|
+
await new Promise(r => setTimeout(r, 1000));
|
|
15
|
+
await strip.fill(0, 255, 0); // Fill all pixels green, (r=0–255, g=0–255, b=0–255, w=0–255) → void
|
|
16
|
+
await new Promise(r => setTimeout(r, 1000));
|
|
17
|
+
await strip.fill(0, 0, 255); // Fill all pixels blue, (r=0–255, g=0–255, b=0–255, w=0–255) → void
|
|
18
|
+
await new Promise(r => setTimeout(r, 1000));
|
|
19
|
+
await strip.fill(0, 0, 0, 255); // Fill all pixels white (W channel), (r=0–255, g=0–255, b=0–255, w=0–255) → void
|
|
20
|
+
await new Promise(r => setTimeout(r, 1000));
|
|
21
|
+
await strip.off(); // Turn off all pixels, () → void
|
|
22
|
+
await connection.close();
|
|
23
|
+
})();
|
|
@@ -1,64 +1,66 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const {
|
|
3
|
+
const { NeoPixelConnection } = require('../../../src/connection/neopixel');
|
|
4
4
|
const { WS2812BFull } = require('../../../src/chips/led/ws2812b');
|
|
5
5
|
|
|
6
6
|
const SPI_BUS = parseInt(process.env.SPI_BUS || '0', 10);
|
|
7
7
|
const SPI_DEVICE = parseInt(process.env.SPI_DEVICE || '0', 10);
|
|
8
8
|
|
|
9
|
-
const
|
|
10
|
-
const strip = new WS2812BFull(
|
|
9
|
+
const connection = new NeoPixelConnection(SPI_BUS, SPI_DEVICE); // Create NeoPixel connection, (busNumber, deviceNumber)
|
|
10
|
+
const strip = new WS2812BFull(connection, 8); // Create WS2812B full driver, (connection, n=8 pixels)
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
(async () => {
|
|
13
|
+
// fill — set all pixels and send immediately
|
|
14
|
+
await strip.fill(255, 0, 0); // Fill all pixels with one colour, (r=0–255, g=0–255, b=0–255) → void
|
|
15
|
+
// stores GRB in buffer and calls connection.write()
|
|
15
16
|
|
|
16
|
-
// set individual pixels then show
|
|
17
|
-
strip.set_pixel(0, 255, 0, 0);
|
|
17
|
+
// set individual pixels then show
|
|
18
|
+
strip.set_pixel(0, 255, 0, 0); // Set pixel 0 in buffer (no send), (index=0–n-1, r=0–255, g=0–255, b=0–255) → void
|
|
18
19
|
// writes G,R,B bytes into internal buffer at position index*3
|
|
19
|
-
strip.set_pixel(1, 0, 255, 0);
|
|
20
|
+
strip.set_pixel(1, 0, 255, 0); // Set pixel 1 in buffer (no send), (index=0–n-1, r=0–255, g=0–255, b=0–255) → void
|
|
20
21
|
// writes G,R,B bytes into internal buffer at position index*3
|
|
21
|
-
strip.set_pixel(2, 0, 0, 255);
|
|
22
|
+
strip.set_pixel(2, 0, 0, 255); // Set pixel 2 in buffer (no send), (index=0–n-1, r=0–255, g=0–255, b=0–255) → void
|
|
22
23
|
// writes G,R,B bytes into internal buffer at position index*3
|
|
23
|
-
strip.show();
|
|
24
|
-
// applies brightness scaling then calls
|
|
24
|
+
await strip.show(); // Transmit buffer to strip, () → void
|
|
25
|
+
// applies brightness scaling then calls connection.write()
|
|
25
26
|
|
|
26
|
-
// set_pixels — write multiple pixels at once
|
|
27
|
-
strip.set_pixels([[255,0,0],[0,255,0],[0,0,255],
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
// set_pixels — write multiple pixels at once
|
|
28
|
+
strip.set_pixels([[255,0,0],[0,255,0],[0,0,255], // Set pixels from array of [r,g,b], (colors=Array<[r,g,b]>) → void
|
|
29
|
+
[255,255,0],[0,255,255],[255,0,255],
|
|
30
|
+
[128,128,128],[255,255,255]]);
|
|
30
31
|
// writes entries sequentially from pixel 0; ignores extras beyond strip length
|
|
31
|
-
strip.show();
|
|
32
|
-
// applies brightness scaling then calls
|
|
32
|
+
await strip.show(); // Transmit buffer to strip, () → void
|
|
33
|
+
// applies brightness scaling then calls connection.write()
|
|
33
34
|
|
|
34
|
-
// brightness — global scale applied at show() time
|
|
35
|
-
strip.brightness = 64;
|
|
35
|
+
// brightness — global scale applied at show() time
|
|
36
|
+
strip.brightness = 64; // Set global brightness, (value=0–255)
|
|
36
37
|
// stored value is scaled: sent = stored * brightness / 255
|
|
37
|
-
strip.show();
|
|
38
|
-
// applies brightness scaling then calls
|
|
39
|
-
strip.brightness = 255;
|
|
38
|
+
await strip.show(); // Transmit buffer to strip, () → void
|
|
39
|
+
// applies brightness scaling then calls connection.write()
|
|
40
|
+
strip.brightness = 255; // Set global brightness, (value=0–255)
|
|
40
41
|
// stored value is scaled: sent = stored * brightness / 255
|
|
41
42
|
|
|
42
|
-
// fill_hsv — fill all pixels from HSV colour
|
|
43
|
-
strip.fill_hsv(0.0, 1.0, 1.0);
|
|
43
|
+
// fill_hsv — fill all pixels from HSV colour
|
|
44
|
+
await strip.fill_hsv(0.0, 1.0, 1.0); // Fill all pixels with HSV colour and send, (h=0.0–1.0, s=0.0–1.0, v=0.0–1.0) → void
|
|
44
45
|
// converts HSV to RGB then calls fill(); hue 0.0 = red
|
|
45
|
-
strip.fill_hsv(0.333, 1.0, 1.0);
|
|
46
|
+
await strip.fill_hsv(0.333, 1.0, 1.0); // Fill all pixels with HSV colour and send, (h=0.0–1.0, s=0.0–1.0, v=0.0–1.0) → void
|
|
46
47
|
// converts HSV to RGB then calls fill(); hue 0.333 = green
|
|
47
|
-
strip.fill_hsv(0.667, 1.0, 1.0);
|
|
48
|
+
await strip.fill_hsv(0.667, 1.0, 1.0); // Fill all pixels with HSV colour and send, (h=0.0–1.0, s=0.0–1.0, v=0.0–1.0) → void
|
|
48
49
|
// converts HSV to RGB then calls fill(); hue 0.667 = blue
|
|
49
50
|
|
|
50
|
-
// rotate — shift pixel buffer left, then show
|
|
51
|
-
strip.set_pixels([[255, 0, 0], ...Array(7).fill([0, 0, 0])]); // Set pixels from array of [r,g,b], (colors=Array<[r,g,b]>) → void
|
|
51
|
+
// rotate — shift pixel buffer left, then show
|
|
52
|
+
strip.set_pixels([[255, 0, 0], ...Array(7).fill([0, 0, 0])]); // Set pixels from array of [r,g,b], (colors=Array<[r,g,b]>) → void
|
|
52
53
|
// writes entries sequentially from pixel 0; ignores extras beyond strip length
|
|
53
|
-
strip.show();
|
|
54
|
-
// applies brightness scaling then calls
|
|
55
|
-
for (let i = 0; i < 7; i++) {
|
|
56
|
-
|
|
54
|
+
await strip.show(); // Transmit buffer to strip, () → void
|
|
55
|
+
// applies brightness scaling then calls connection.write()
|
|
56
|
+
for (let i = 0; i < 7; i++) {
|
|
57
|
+
strip.rotate(1); // Rotate pixel buffer left, (steps=1) → void
|
|
57
58
|
// shifts buffer by steps pixel positions; wraps around; does not send
|
|
58
|
-
|
|
59
|
-
// applies brightness scaling then calls
|
|
60
|
-
}
|
|
59
|
+
await strip.show(); // Transmit buffer to strip, () → void
|
|
60
|
+
// applies brightness scaling then calls connection.write()
|
|
61
|
+
}
|
|
61
62
|
|
|
62
|
-
strip.off();
|
|
63
|
+
await strip.off(); // Turn off all pixels, () → void
|
|
63
64
|
// equivalent to fill(0, 0, 0)
|
|
64
|
-
|
|
65
|
+
await connection.close();
|
|
66
|
+
})();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const {
|
|
3
|
+
const { NeoPixelConnection } = require('../../../src/connection/neopixel');
|
|
4
4
|
const { WS2812BFull } = require('../../../src/chips/led/ws2812b');
|
|
5
5
|
|
|
6
6
|
const SPI_BUS = parseInt(process.env.SPI_BUS || '0', 10);
|
|
@@ -12,8 +12,8 @@ const RAINBOW_DURATION = 10000;
|
|
|
12
12
|
const STROBE_DURATION = 2000;
|
|
13
13
|
const STROBE_HALF = 50;
|
|
14
14
|
|
|
15
|
-
const
|
|
16
|
-
const strip = new WS2812BFull(
|
|
15
|
+
const connection = new NeoPixelConnection(SPI_BUS, SPI_DEVICE); // Create NeoPixel connection, (busNumber, deviceNumber)
|
|
16
|
+
const strip = new WS2812BFull(connection, N_PIXELS); // Create WS2812B full driver, (connection, n=N_PIXELS pixels)
|
|
17
17
|
strip.brightness = 180; // Set global brightness, (value=0–255)
|
|
18
18
|
|
|
19
19
|
function hsvToRgb(h, s, v) {
|
|
@@ -40,13 +40,13 @@ function hsvToRgb(h, s, v) {
|
|
|
40
40
|
let hueOffset = 0;
|
|
41
41
|
let lastPrint = Date.now();
|
|
42
42
|
|
|
43
|
-
function rainbowFrame() {
|
|
43
|
+
async function rainbowFrame() {
|
|
44
44
|
for (let i = 0; i < N_PIXELS; i++) {
|
|
45
45
|
const h = (hueOffset + i / N_PIXELS) % 1.0;
|
|
46
46
|
const [r, g, b] = hsvToRgb(h, 1.0, 1.0);
|
|
47
47
|
strip.set_pixel(i, r, g, b); // Set pixel i to rainbow hue, (index=0–n-1, r=0–255, g=0–255, b=0–255) → void
|
|
48
48
|
}
|
|
49
|
-
strip.show();
|
|
49
|
+
await strip.show(); // Transmit buffer to strip, () → void
|
|
50
50
|
hueOffset = (hueOffset + 1.0 / (N_PIXELS * 2)) % 1.0;
|
|
51
51
|
const now = Date.now();
|
|
52
52
|
if (now - lastPrint >= 1000) {
|
|
@@ -56,8 +56,8 @@ function rainbowFrame() {
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
const rainbowStart = Date.now();
|
|
59
|
-
const rainbowTimer = setInterval(() => {
|
|
60
|
-
rainbowFrame();
|
|
59
|
+
const rainbowTimer = setInterval(async () => {
|
|
60
|
+
await rainbowFrame();
|
|
61
61
|
if (Date.now() - rainbowStart >= RAINBOW_DURATION) {
|
|
62
62
|
clearInterval(rainbowTimer);
|
|
63
63
|
startStrobe();
|
|
@@ -68,14 +68,14 @@ const rainbowTimer = setInterval(() => {
|
|
|
68
68
|
// Uses brightness=255 for maximum intensity then brightness=0 for off,
|
|
69
69
|
// demonstrating non-destructive brightness scaling — pixel values in the
|
|
70
70
|
// buffer are never zeroed. ---
|
|
71
|
-
function startStrobe() {
|
|
71
|
+
async function startStrobe() {
|
|
72
72
|
strip.brightness = 255; // Set global brightness, (value=0–255)
|
|
73
|
-
strip.fill(255, 255, 255);
|
|
73
|
+
await strip.fill(255, 255, 255); // Pre-load white into buffer, (r=0–255, g=0–255, b=0–255) → void
|
|
74
74
|
let state = true;
|
|
75
75
|
const strobeStart = Date.now();
|
|
76
|
-
const strobeTimer = setInterval(() => {
|
|
76
|
+
const strobeTimer = setInterval(async () => {
|
|
77
77
|
strip.brightness = state ? 255 : 0; // Set global brightness, (value=0–255)
|
|
78
|
-
strip.show();
|
|
78
|
+
await strip.show(); // Transmit buffer to strip, () → void
|
|
79
79
|
state = !state;
|
|
80
80
|
if (Date.now() - strobeStart >= STROBE_DURATION) {
|
|
81
81
|
clearInterval(strobeTimer);
|
|
@@ -89,13 +89,13 @@ function startRainbowContinuous() {
|
|
|
89
89
|
strip.brightness = 180; // Set global brightness, (value=0–255)
|
|
90
90
|
hueOffset = 0;
|
|
91
91
|
lastPrint = Date.now();
|
|
92
|
-
setInterval(() => {
|
|
93
|
-
rainbowFrame();
|
|
92
|
+
setInterval(async () => {
|
|
93
|
+
await rainbowFrame();
|
|
94
94
|
}, FRAME_MS);
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
-
process.on('SIGINT', () => {
|
|
98
|
-
strip.off();
|
|
99
|
-
|
|
97
|
+
process.on('SIGINT', async () => {
|
|
98
|
+
await strip.off();
|
|
99
|
+
await connection.close();
|
|
100
100
|
process.exit(0);
|
|
101
101
|
});
|
|
@@ -1,22 +1,21 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const {
|
|
3
|
+
const { NeoPixelConnection } = require('../../../src/connection/neopixel');
|
|
4
4
|
const { WS2812BMinimal } = require('../../../src/chips/led/ws2812b');
|
|
5
5
|
|
|
6
6
|
const SPI_BUS = parseInt(process.env.SPI_BUS || '0', 10);
|
|
7
7
|
const SPI_DEVICE = parseInt(process.env.SPI_DEVICE || '0', 10);
|
|
8
8
|
|
|
9
|
-
const
|
|
10
|
-
const strip = new WS2812BMinimal(
|
|
9
|
+
const connection = new NeoPixelConnection(SPI_BUS, SPI_DEVICE); // Create NeoPixel connection, (busNumber, deviceNumber)
|
|
10
|
+
const strip = new WS2812BMinimal(connection, 30); // Create WS2812B driver, (connection, n=30 pixels)
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}, 1000);
|
|
12
|
+
(async () => {
|
|
13
|
+
await strip.fill(255, 0, 0); // Fill all pixels red, (r=0–255, g=0–255, b=0–255) → void
|
|
14
|
+
await new Promise(r => setTimeout(r, 1000));
|
|
15
|
+
await strip.fill(0, 255, 0); // Fill all pixels green, (r=0–255, g=0–255, b=0–255) → void
|
|
16
|
+
await new Promise(r => setTimeout(r, 1000));
|
|
17
|
+
await strip.fill(0, 0, 255); // Fill all pixels blue, (r=0–255, g=0–255, b=0–255) → void
|
|
18
|
+
await new Promise(r => setTimeout(r, 1000));
|
|
19
|
+
await strip.off(); // Turn off all pixels, () → void
|
|
20
|
+
await connection.close();
|
|
21
|
+
})();
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { NeoPixelConnection } = require('../../../src/connection/neopixel');
|
|
4
|
+
const { WS2814Full } = require('../../../src/chips/led/ws2814');
|
|
5
|
+
|
|
6
|
+
const SPI_BUS = parseInt(process.env.SPI_BUS || '0', 10);
|
|
7
|
+
const SPI_DEVICE = parseInt(process.env.SPI_DEVICE || '0', 10);
|
|
8
|
+
|
|
9
|
+
const connection = new NeoPixelConnection(SPI_BUS, SPI_DEVICE); // Create NeoPixel connection, (busNumber, deviceNumber)
|
|
10
|
+
const strip = new WS2814Full(connection, 8); // Create WS2814 full driver, (connection, n=8 pixels)
|
|
11
|
+
|
|
12
|
+
(async () => {
|
|
13
|
+
// fill — set all pixels and send immediately
|
|
14
|
+
await strip.fill(255, 0, 0); // Fill all pixels with one colour, (r=0–255, g=0–255, b=0–255, w=0–255) → void
|
|
15
|
+
// stores RGBW in buffer (identity order) and calls connection.write()
|
|
16
|
+
|
|
17
|
+
// fill with white channel
|
|
18
|
+
await strip.fill(0, 0, 0, 255); // Fill all pixels using W channel, (r=0–255, g=0–255, b=0–255, w=0–255) → void
|
|
19
|
+
// w=255 activates dedicated white LED element; RGB channels stay dark
|
|
20
|
+
|
|
21
|
+
// set individual pixels then show
|
|
22
|
+
strip.set_pixel(0, 255, 0, 0); // Set pixel 0 in buffer (no send), (index=0–n-1, r=0–255, g=0–255, b=0–255, w=0–255) → void
|
|
23
|
+
// writes R,G,B,W bytes into internal buffer at position index*4
|
|
24
|
+
strip.set_pixel(1, 0, 255, 0); // Set pixel 1 in buffer (no send), (index=0–n-1, r=0–255, g=0–255, b=0–255, w=0–255) → void
|
|
25
|
+
// writes R,G,B,W bytes into internal buffer at position index*4
|
|
26
|
+
strip.set_pixel(2, 0, 0, 255); // Set pixel 2 in buffer (no send), (index=0–n-1, r=0–255, g=0–255, b=0–255, w=0–255) → void
|
|
27
|
+
// writes R,G,B,W bytes into internal buffer at position index*4
|
|
28
|
+
strip.set_pixel(3, 0, 0, 0, 255); // Set pixel 3 to white in buffer (no send), (index=0–n-1, r=0–255, g=0–255, b=0–255, w=0–255) → void
|
|
29
|
+
// w=255 lights the dedicated white element; RGB remain off
|
|
30
|
+
await strip.show(); // Transmit buffer to strip, () → void
|
|
31
|
+
// applies brightness scaling then calls connection.write()
|
|
32
|
+
|
|
33
|
+
// set_pixels — write multiple pixels at once
|
|
34
|
+
strip.set_pixels([[255,0,0,0],[0,255,0,0],[0,0,255,0], // Set pixels from array of [r,g,b,w], (colors=Array<[r,g,b,w?]>) → void
|
|
35
|
+
[0,0,0,255],[255,200,150,255]]);
|
|
36
|
+
// handles 3- or 4-element tuples; writes entries sequentially from pixel 0
|
|
37
|
+
await strip.show(); // Transmit buffer to strip, () → void
|
|
38
|
+
// applies brightness scaling then calls connection.write()
|
|
39
|
+
|
|
40
|
+
// brightness — global scale applied at show() time
|
|
41
|
+
strip.brightness = 64; // Set global brightness, (value=0–255)
|
|
42
|
+
// stored value is scaled: sent = stored * brightness / 255
|
|
43
|
+
await strip.show(); // Transmit buffer to strip, () → void
|
|
44
|
+
// applies brightness scaling then calls connection.write()
|
|
45
|
+
strip.brightness = 255; // Set global brightness, (value=0–255)
|
|
46
|
+
// stored value is scaled: sent = stored * brightness / 255
|
|
47
|
+
|
|
48
|
+
// fill_hsv — fill all pixels from HSV colour (white=0)
|
|
49
|
+
await strip.fill_hsv(0.0, 1.0, 1.0); // Fill all pixels with HSV colour and send, (h=0.0–1.0, s=0.0–1.0, v=0.0–1.0) → void
|
|
50
|
+
// converts HSV to RGB (w=0) then calls fill(); hue 0.0 = red
|
|
51
|
+
await strip.fill_hsv(0.333, 1.0, 1.0); // Fill all pixels with HSV colour and send, (h=0.0–1.0, s=0.0–1.0, v=0.0–1.0) → void
|
|
52
|
+
// converts HSV to RGB (w=0) then calls fill(); hue 0.333 = green
|
|
53
|
+
await strip.fill_hsv(0.667, 1.0, 1.0); // Fill all pixels with HSV colour and send, (h=0.0–1.0, s=0.0–1.0, v=0.0–1.0) → void
|
|
54
|
+
// converts HSV to RGB (w=0) then calls fill(); hue 0.667 = blue
|
|
55
|
+
|
|
56
|
+
// rotate — shift pixel buffer left, then show
|
|
57
|
+
strip.set_pixels([[255,0,0,0], ...Array(7).fill([0,0,0,0])]); // Set pixels from array of [r,g,b,w], (colors=Array<[r,g,b,w?]>) → void
|
|
58
|
+
// handles 3- or 4-element tuples; writes entries sequentially from pixel 0
|
|
59
|
+
await strip.show(); // Transmit buffer to strip, () → void
|
|
60
|
+
// applies brightness scaling then calls connection.write()
|
|
61
|
+
for (let i = 0; i < 7; i++) {
|
|
62
|
+
strip.rotate(1); // Rotate pixel buffer left, (steps=1) → void
|
|
63
|
+
// shifts buffer by steps pixel positions; wraps around; does not send
|
|
64
|
+
await strip.show(); // Transmit buffer to strip, () → void
|
|
65
|
+
// applies brightness scaling then calls connection.write()
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
await strip.off(); // Turn off all pixels, () → void
|
|
69
|
+
// equivalent to fill(0, 0, 0, 0)
|
|
70
|
+
await connection.close();
|
|
71
|
+
})();
|