math math.add, subtract, subtractFrom, multiplyBy, divideBy, divideInto, squareRoot, etc. the usual set of basic arithmetic math.constant(c) EG: math.constant(10) -> always outputs 10. EG: to set a light to half brightness, math.constant(50%) -> lamp.brightness math.toggle, output switches between 0 and 1 every time it gets a 1. Thus: define switch.flip : math.toggle -> switch.value math.isLessThan(x), isGreaterThan(x), etc. Output a 1 if so, a 0 if not. EG, to take a pot which outputs 0 to 100 and have it control a switch that wants 0/1, pot.value -> math.isGreaterThan(50) -> switch.value math.stopIfLessThen(x), stopIfGreaterThan(x), etc. Stops this iteration of cmd. These are macros, combining the above isLessThan, isGreaterThan, etc, with do.stop. EG: define math.stopIfLessThan(v) : math.isLessThan(v) -> do.stop math.smoothMovingAverage(n) output equals average of the last n inputs. EG: do.every(10) -> sensor.value -> math.smoothMovingAverage(5) -> etc here "etc" receives the average of the last 5 inputs. math.smoothGaussian(n) same as smoothMovingAverage, but weights the last n samples with a "gaussian" weighting. do.every(10) -> sensor.value -> math.smoothGaussian(5) -> etc math.fft(nSamples,nBands), outputs an nBand spectrum analysis after nSamples sent to it. math.digitalFilter, many types, low pass, band pass, etc. math.addReverb(percent,delay) adds a percentage of the signal back in after delay time. EG: math.addReverb(20,100 ms) buffers the signal for at least 100 ms, generates output = current sample + 20% of sample from 100 ms ago. math.pulseDetector, output equals 0 so long as repeated inputs are steady, else 1 when it begins to change by a steep gradient. Only outputs the 1 once, then returns to 0 until input returns to steady state again, and stays 0 until another leadingEdge comes. EG: do.every(50ms) : mike.volume -> math.pulseDetector -> switch.flip Clap on, clap off! Or: lightSensor.value -> math.pulseDetector -> switch.flip distanceSensor.value -> math.pulseDetector -> switch.flip Wave a hand over a photodetector, or a distance sensor, to flip the switch. Wax on, wax off. math.sineWaveGenerator(amplitude,phase,dcBias,nSamples) generates the next sample of a sine wave each time it is invoked, with n samples per cycle. EG: do.atFrequency(64000) : math.sineWaveGenerator(1,0,0,64) -> speaker.rawValue this plays a 1000 Hz tone with 64 samples for each wave. math.count(initial value, final value, increment, endActionCode) Counts, each time it is invoked. Starts count with initial value, counts to final value. EndActionCode specifies: 1: terminate, output final value forever. 2: start over 3: negate increment and count back down. EG: do.every(0.1 sec) : math.count(0,100,1,1) -> lamp.brightness This takes brightness smoothly from 0 to 100 over a period of 10 seconds.] math.statistics(n,mode) computes mean, median, mode, standard deviation of last n inputs. Outputs nothing until n points have gone by, then outputs 6 numbers. If mode=1, starts over for the next n points. If mode=2, re-computes with each new point. This is very much like math.smoothMovingAverage, but with more than averages, with all 6 stats. math.etcetc - User can add functions. Can implement any custom formula.