# Counter

> Count rising edges of a trigger lane, with step, limit, wrap and reset. Lane 1 is the normalised count, lane 2 the raw count.

Source: https://docs.tune.toys/nodes/ctl.counter/

Counter counts the rising edges of a trigger lane, with a step, a limit, wrapping and a reset input.

## What it does

Each rising edge on trigger adds Step to the count; a negative Step counts down. The count is kept between 0 and Limit: with Clamp it stops at the limit, with Wrap it returns to 0 once it passes it. A rising edge on reset returns the count to its start. The output has two lanes: lane 1 is the count divided by Limit, from 0 to 1, and lane 2 is the raw count.

### Events

The `wrap` outlet sends an event: it is 1 for one block whenever a step carries the count past Limit or below 0, whether Wrap brings it back to 0 or Clamp holds it at the edge, and 0 otherwise. A reset never counts as a wrap. Cable it into a trigger input, such as another Counter or [Sample and hold](https://docs.tune.toys/nodes/ctl.hold/), to do something once per lap.

## When to use it

Use it for scoreboards, step counters and anything that advances on events. Feed it from [Compare](https://docs.tune.toys/nodes/std.compare/) in Trigger mode, or straight from a square [Control LFO](https://docs.tune.toys/nodes/ctl.lfo/) as a clock. Use lane 1 for a normalised position and lane 2 for the whole number.

## Ports

<!-- ports:start -->

| Port      | Direction | Signal  | Lanes |
| --------- | --------- | ------- | ----- |
| `trigger` | Input     | Control | 1     |
| `reset`   | Input     | Control | 1     |
| `control` | Output    | Control | 2     |
| `wrap`    | Output    | Control | 1     |

<!-- ports:end -->

## Parameters

<!-- parameters:start -->

| Parameter | Label | Range     | Default | Unit | Scale  | Notes                                                                                     |
| --------- | ----- | --------- | ------- | ---- | ------ | ----------------------------------------------------------------------------------------- |
| `limit`   | Limit | 1 to 1000 | 10      |      | linear | Count value that maps to 1 on the normalised lane and where wrapping or clamping happens. |
| `step`    | Step  | -10 to 10 | 1       |      | linear | Amount added on each trigger; negative counts down.                                       |
| `wrap`    | Wrap  | 0 to 1    | 0       |      | linear | Wrap past the limit back to 0 instead of clamping. Choices: 0 Clamp, 1 Wrap.              |

<!-- parameters:end -->

### Limit (`limit`)

The count that maps to 1 on the normalised lane, and where wrapping or clamping happens. 1 to 1000, whole numbers.

### Step (`step`)

The amount added on each trigger, -10 to 10. Negative counts down.

### Wrap (`wrap`)

Clamp holds the count at the limit; Wrap returns it to 0 instead. A discrete choice.

## Tips

- Use [Select lanes](https://docs.tune.toys/nodes/ctl.select/) to pick the normalised or raw lane.
- Both inputs are single lanes, so cable one lane into each.
- `wrap` is a one-block pulse, like [Compare](https://docs.tune.toys/nodes/std.compare/) in Trigger mode: cable it into a trigger, not into a parameter that should glide.

## See also

[Compare](https://docs.tune.toys/nodes/std.compare/), [Sample and hold](https://docs.tune.toys/nodes/ctl.hold/), [Control LFO](https://docs.tune.toys/nodes/ctl.lfo/), [Select lanes](https://docs.tune.toys/nodes/ctl.select/), [Cables](https://docs.tune.toys/concepts/cables/).
