Outputs values that increase or decrease by an increment each time the input reaches a threshold

The Counter widget listens for a peak value from its input, and each time this value is received, it changes the counter output by the increment. For example, every time a button is pushed, the value of DigitalIn transitions from 0 to 1023. The Counter widget can monitor this and increment by 1 each button press. If the “min” is set to 0, and “max” is set to 1, the Counter output will toggle between 1 and 0 each time the button is pressed, creating an on/off button out of a momentary button. Another example would use the Counter to advance through a series of frames in a Flash MovieClip, where “min” is set to the first frame, and “max” is set to the last frame. In this case, the ClipControl widget would use the Counter widget as its input by specifying the instance name of the Counter.

Incrementing and Decrementing with one Counter Widget

Normally, the Counter widget only changes the output count by the amount of the on-screen increment. This increment can be positive or negative to increase or decrease the count respectively. But the count can only be change by this increment, typically (with a positive number) increasing the count.

Sometimes you want your application to both increment and decrement the count. There are two ways to do this. You can use two separate sensors and feed them both into the counter widget where one causes an increment and the other causes the decrement. Or you can use a single sensor that generates a positive number to increment, and a negative number to decrement (a knob could be made to do this by setting the min setting in an AnalogIn to -500).

Use two inputs

Use the inputDecrement as a second input source to decrement. Values coming into the Counter widget’s normal inputSource will use the on-screen increment value. Values coming from the inputDecrement will change the count by the opposite amount. For example, with the increment set to 1, a value above the threshold of 500 from inputSource will increase the count by 1, and a value from inputDecrement above 500 will reduce the count by 1.

Use a negative number

If the Counter widget receives a value from inputSource that’s a negative number that’s greater than or equal to the threshold, then the “increment” is subtracted from the current output value rather than added. For example with the settings shown in the image of the widget above, an input value of 500 would cause an increment of 1, and a -500 would cause a decrement of 1.

On Screen Features

  • threshold: The threshold for incrementing the Counter output. If the most recent input value is greater than or equal to THRESHOLD after being less than THRESHOLD, the output value will be incremented by INCREMENT.
  • increment: The amount the Counter output will be incremented each time THRESHOLD is reached. Increment can be either positive or negative (for decreasing the value of the output each time).
  • min: The lowest value of the Counter output. If the INCREMENT value is negative, and the output is at MIN, the next time the THRESHOLD is received, the output will be MAX.
  • max: The highest value of the Counter output. If the THRESHOLD is reached when the output is at MAX, the next value of output will be MIN.


  • invisible: if set to “yes”, the widget will disappear when the Flash movie is run
  • inputSource: the instance name of the source the widget listens to, e.g AnalogIn or DigitalIn.
  • inputDecrement: optional instance name of the source the widget listens to decrement the count. Values from this input are displayed as a negative of the value received. So if a value of 500 is input, it will be displayed as -500.

Code Interface

The Counter code interface enables the user to reset or change the count from code.

In the below example, the code assumes that there is a Counter widget on the stage with the instance name “myCounter”.


Sets the current count as visible in the OUT field. Sends this new value to the output of the Counter widget.


Last modified April 4th, 2012