-
Notifications
You must be signed in to change notification settings - Fork 1
Coding the Tree pt. 2 (advanced)
Diamond edited this page Dec 1, 2023
·
2 revisions
This page is the continuation of the Coding the Tree pt. 1 (simple) page. If you have not read it, please do! This page will assume that you already know what Part 1 is talking about.
Aside from the 2D image API, the server also exposes an API that lets you directly change the LEDs. Within christmas-client-js
, you may use the LEDController
class for this:
import { LEDController } from "christmas-client-js";
const url = "<url goes here...>";
const client = new LEDController(url);
await client.connect();
// Get the number of LEDs from the server.
const numLEDs = (await client.getLEDs()).length;
// Create an array containing n white LEDs.
const whiteLEDs = Array(numLEDs).fill(0xFFFFFF);
// Send this to the server.
client.setLEDs(whiteLEDs);
Of course, setting the LEDs to all white isn't very impressive. We still want to be able to make cool patterns on a 2D surface with them, like how we could with the simpler Canvas
API. For this, you can request the list of LED coordinates from the server:
const coords = await client.getLEDPoints();
console.log(`the LED coordinates are:`, coords);
Using this, you can manually perform any sort of animations that you may want.