# Glowscript

## asynchronous programming language

Glowscript is a simple yet powerful asynchronous programming language for creating animations on smart LED strips, including DotStars and NeoPixels.

## Features

• A single glowscript program can run 256 independent animation threads and drive over 1000 LEDs.

• LEDs can be grouped and assigned to multiple animation threads to create complex light patterns.

• Animation z-ordering allows superimposed animations.

• Timing instructions permit LED color changes as rapidly as every millisecond or as slowly as every month.

• Color data compression reduces complex animations to a compact footprint.

## Syntax

glowImmediate

 syntax glowImmediate: [led1,led2,…] color action Instantly sets the color of the specified LEDs. e.g. 1 glowImmediate: [led5] green e.g. 2 glowImmediate: [led1,led2,led7] red

glowRamp

 syntax glowRamp: [led1,led2,…] color1 to color2 in timeDuration action Instantly sets color1 on the specified LEDs, then transitions color1 to color2 over the specified time duration. e.g. 1 glowRamp: [led15,led4] green to blue in 100ms e.g. 2 glowRamp: [led19] red to orange in 5s

pause

 syntax pause: duration action Pause current thread for the specified duration. Time units can be milli-seconds, seconds, minutes, hours, or ticks. Minimum pause duration is 1 millisecond. Maximum pause duration is 1080 hours (45 days). The pause duration must be a multiple of the device:tickIntervalMillisecs parameter value, which is the time interval between animation update cycles. e.g. 1 pause: 5ms e.g. 2 pause: 30s e.g. 3 pause: 20m e.g. 4 pause: 1h e.g. 5 pause: 40t

here

 syntax here: bookmarkName action Bookmark a location in the current function. e.g. 1 here: strobeStart

goto

 syntax goto: bookmarkName action Jump to a bookmark in the current function. e.g. 1 goto: strobeStart

call

 syntax call: @targetFunction action Synchronously runs the target function (current function pauses until the target function completes). e.g. 1 call: @redStrobeFunction

repeat

 syntax call: @targetFunction (repeat=N) action Synchronously runs the target function N times (current function pauses until all repetitions of the target function completes). Using the repeat parameter is optional. Minimum repeat value is 1 (same as omitting repeat parameter). Maximum repeat value is 2 billion. Repeat is used in conjuction with the call instruction. e.g. 1 call: @redStrobeFunction (repeat=50)

callAsync

 syntax callAsync: @targetFunc action Asynchronously runs the target function (current function continues immediately after launching the target function). The callAsync instruction can be nested at any level of your code. e.g. 1 callAsync: @blueStrobeFunc

zOrder

 syntax callAsync: @targetFunc (zOrder=N) action Asynchronously runs the target function with a z-order of N (current function continues immediately after launching the target function). When different animation functions act on the same LED(s), the function with the highest z-order controls the LED(s). If threads have the same z-order, then the last-launched thread wins. Z-order values do not need to be consecutive as the compiler uses them as relative values. Using the z-order parameter is optional. Minimum z-order value is 0 (same as omitting z-order parameter). Maximum z-order value is 1000. Z-order is used in conjuction with the callAsync instruction. e.g. 1 callAsync: @blueStrobeFunc (zOrder=2) e.g. 2 callAsync: @lightBeamFunc (zOrder=35)

define

 syntax define: alias='value' action Sets a user-friendly alias for the specified string value. This helps with readability and code-maintenance. e.g. 1 define: strobeLeds='[2,3,4,5,9]' e.g. 2 define: purple='(255,0,255,1)'

Specifying LEDs
LEDs are specified by their numeric position from the start of the LED strip (i.e. 1,2,3 and so on) in the following format: [1,2,3] or [1-3] or [1,2-3]).

Specifying colors/brightness
A color is specified by its red value (0-255), green value (0-255), blue value (0-255), & brightness value (0-31) in the following format: (redVal, greenVal, blueVal, brightVal).

Case sensitivity
Glowscript is case-insensitive.

See animation samples for further usage examples.