Pixelblaze Advanced Features. 

 
 

Connecting a Button

Pixelblaze supports a button on gp0. This pin has a pull-up resistor, and when shorted to ground momentarily will change the pattern. If pressed for more than 3.5 seconds, it will reset the WiFi settings and put Pixelblaze into WiFi setup mode. 

Screen Shot 2018-03-23 at 7.48.15 AM.png

To wire a button, connect the gp0 and the gnd pin to the button. 

Using the Analog to Digital Converter (ADC)

Pixelblaze has a 0-1v range ADC input that can be used in patterns. This can read values from many kinds of sensors or inputs. One possibility is to connect it to a potentiometer to create a dial that controls brightness.

Screen Shot 2018-03-23 at 8.03.33 AM.png

A voltage divider limits the pot's center tap output to 1v.

 

R1 = 3.3*VR1 - VR1

Enter the value of your potentiometer to see the ideal value of R1:

R1 = 23000

Slightly higher values are OK, for example using a standard 24k resistor instead of a 23k resistor will still keep the output voltage under 1v, it will just max out at 0.97v instead of exactly 1v.

To use this in a pattern as a brightness control, multiply the value argument with the readAdc() result:


hsv(h, s, v * readAdc())

You can use this to control all sorts of things!

Websocket API

Pixelblaze is controlled by a websocket connection on port 81. JSON and binary frames are sent to control and edit the patterns.

Getting and Setting Variables

Pattern variables can be controlled over the network using websockets. 

Version 1: If your expression uses but does not initialize some variables, you can set these. They default to 0 if otherwise uninitialized. If you do set them to a value in the pattern, they are overwritten each time and setVars won't take effect.

Version 2: You can export top-level variables to make them public and initialize them to default values. e.g.


export var myVar = 2
export var var2 = 0

 

To set variables, send a JSON text frame like this:


{
	"setVars": {
		"myVar": 3.14159,
		"var2": 42
	}
}

To get variables, send a frame like this:


{
	"getVars": true
}

And you'll get a response with all variables. Note that this will only show variable state AFTER the last pixel has been rendered. 


{
	vars: {
		"myVar": 3.14159, 
		"var2": 42,
		...
	}
}

Listing Patterns (V1 only)


{
	"listPrograms": true
}

The pattern list returned contains the name and id, along with some other fields about storage space in memory.


{
	"programList": [
		{
			"name": "my pattern",
			"id": "x1234567890",
			"sourceSize": 123,
			"globalSourceSize": 123,
			"compiledSize": 134,
			"imgSize": 5123
		}, ...
	]
}

Changing The Active Pattern

With a pattern ID handy, you can activate any previously stored pattern. This change is saved and will persist if the device restarts. 


{
	"activeProgramId": "x1234567890"
}