My latest lighting project which is Electronic Minora
(just in case, here is a latest PB code):
// Variables for External Control
export var nCandles = 3
// Internal Constants
var matriWwidth = 32
var matrixHeight = 8
var candlesMaxNumber = 8
// Pre-defined Candle Base Width
var candleBaseWidth =
[
[3, 0, 0, 0, 0, 0, 0, 0],
[3, 3, 0, 0, 0, 0, 0, 0],
[3, 3, 3, 0, 0, 0, 0, 0],
[3, 3, 3, 3, 0, 0, 0, 0],
[3, 3, 3, 3, 3, 0, 0, 0],
[3, 3, 3, 3, 3, 3, 0, 0],
[3, 3, 3, 3, 3, 3, 3, 0],
[3, 3, 3, 3, 3, 3, 3, 3]
]
// Pre-defined Candle Base Height
var candleBaseHeight =
[
[3, 0, 0, 0, 0, 0, 0, 0],
[3, 3, 0, 0, 0, 0, 0, 0],
[2, 3, 2, 0, 0, 0, 0, 0],
[2, 3, 3, 2, 0, 0, 0, 0],
[2, 3, 4, 3, 2, 0, 0, 0],
[1, 2, 3, 3, 2, 1, 0, 0],
[1, 2, 3, 4, 3, 2, 1, 0],
[1, 2, 3, 4, 4, 3, 2, 1]
]
// Pre-defined Candle Flame Offset
// -1 : Candle Flame is narrowed by 2 vs Candle Base
// 0 : Candle Flame is equal to Candle Bas
// +1 : Candle Flame is widened by 2 vs Candle Base
var candleFlameOffset =
[
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0]
]
// Pre-defined Candle Flame Height
// -x increases Candle Flame
// +x reduces Candle Flame
var candleFireHeight =
[
[-0.1, 0, 0, 0, 0, 0, 0, 0],
[-0.1, -0.1, 0, 0, 0, 0, 0, 0],
[ 0.1, -0.1, 0.1, 0, 0, 0, 0, 0],
[ 0.1, -0.1, -0.1, 0.1, 0, 0, 0, 0],
[ 0.2, 0.1, -0.1, 0.1, 0.2, 0, 0, 0],
[ 0.4, 0.2, -0.1, -0.1, 0.2, 0.4, 0, 0],
[ 0.5, 0.4, 0.2, -0.1, 0.2, 0.4, 0.5, 0],
[ 0.6, 0.4, 0.2, -0.1, -0.1, 0.2, 0.4, 0.6]
]
// Predefined Candle's Offsets
// Defines a location for the First Base Pixel
var candleOffset =
[
// X - Candle Offset per Candle
// Y - Candle Numbers
[15, 0, 0, 0, 0, 0, 0, 0],
[ 9, 20, 0, 0, 0, 0, 0, 0],
[ 6, 15, 24, 0, 0, 0, 0, 0],
[ 4, 11, 18, 25, 0, 0, 0, 0],
[ 3, 9, 15, 21, 27, 0, 0, 0],
[ 2, 7, 12, 17, 22, 27, 0, 0],
[ 1, 5, 10, 14, 19, 23, 28, 0],
[ 0, 4, 8, 12, 16, 20, 24, 28]
]
// Candle's Base Brightness and Color
var vBase = 0.08
var hBase = 0.65
var sBase = 0.1
// Candle's Fire Brightness and Color
var vFire = 1
var hFire = 0.05
var sFire = 1
// Calculated Parameters
var t1 = 0;
export function beforeRender(delta)
{
// Build a timer using accumulated milliseconds
// Denominator controls speed of noise field traversal (flicker speed)
// The % 256 is used to keep values in a reasonable range for
// input to noise function.
t1 = (t1 + delta/2000) % 256;
}
export function render2D(index, x, y)
{
X = floor(x * matriWwidth)
Y = floor(y * matrixHeight)
candleNumber = floor(X / (matriWwidth / nCandles))
candleStartX = candleOffset[nCandles - 1][candleNumber]
if (Y >= (matrixHeight - candleBaseHeight[nCandles - 1][candleNumber]))
{
candleStartX = candleOffset[nCandles - 1][candleNumber]
candleStopX = (candleStartX + candleBaseWidth[nCandles - 1][candleNumber])
}
else
{
candleStartX = candleOffset[nCandles - 1][candleNumber] - candleFlameOffset[nCandles - 1][candleNumber]
candleStopX = (candleStartX + candleBaseWidth[nCandles - 1][candleNumber]) + (2 * candleFlameOffset[nCandles - 1][candleNumber])
}
if ((X >= candleStartX) && (X < candleStopX))
{
if (Y >= (matrixHeight - candleBaseHeight[nCandles - 1][candleNumber]))
{
v = vBase
h = hBase
s = sBase
}
else
{
// generate positive perlin noise value for current coordinates, offset by timer
// this will be used both for pixel brightness and to determine the maximum
// height of the current candle ()
v = abs(perlin(Y+t1, X-t1, 0.5, PI))
// if pixel is above max flame height, turn it off. Otherwise
// set it to perlin noise value.
v = (y >= (vFire * v) + candleFireHeight[nCandles - 1][candleNumber]) ? v : 0;
h = hFire
s = sFire
}
}
else
{
v = 0
}
hsv(h, s, v)
}
got a lot of attention from our friends with a request to build one for them.
All my PB projects are designed to be controlled by Hubitat Elevation home automation controller with excellent driver designed by @zranger1
The problem is - nobody of our friends have anything like this.
I did search forum and net for the options how to control a PBs remotely but so far did not find any reasonably simple simple solutions. (Yes, I can use something to toggle PBs GPIO pins but this required extra hardware).
My question is - is it possible to create something in the Web Browser (http post?) for updating exported PB variables?
For this Minore project all what I need is an ability to update nCandles exported variable and turn On/Off the entire thing (set built-in brightness variable to 0/1).
I am sure, it is possible to write a relatively simple Android (and/or Apple) app to send these commands to PB but is well beyond my capabilities.
Any ideas are very welcome.
PS. Installing any extra SW such as Python, etc. unfortunately not an option.