How about a couple of JS namespaces?
In this pattern, imagine a bunch of people wielding Pico+ LED swords:
- H: Each sword’s colour is determined by the next wielder’s motions.
- S: Someone has a browser open to the Leader PB web UI to control everyone’s saturation.
- V: Everyone controls the brightness of their own sword via a GPIO knob.
// Writes to global variables are sent to the master at a tunable frequency.
// Last writer wins. No built-in consensus algorithm.
// The master broadcasts the latest value at another tunable frequency.
var global.Hue = array(nodeCount)
// Only the leader can write and broadcast this variable at yet another tunable frequency.
// It's read-only for followers.
var leader.Saturation = 1
// Normal device-local variable set from local GPIO
var Value = 0
export function render(index) {
hsv(
global.Hue[(nodeId() + 1) % nodeCount],
leader.Saturation,
Value * (index/pixelcount)
)
}
export function beforeRender(delta) {
global.Hue[nodeId()] = something_interesting(delta, sixAxis)
Value = analogRead(GPIO_PIN_BRIGHTNESS)
}
// This function only executes on the leader
export leader function sliderSaturation(v) {
leader.Saturation = v
}