pxt-ev3/docs/reference/motors/motor/clear-counts.md

35 lines
1016 B
Markdown
Raw Normal View History

# clear Counts
Set all counters for the motor back to zero.
```sig
motors.largeA.clearCounts()
```
The counters for a motor are: **tacho**, **angle**, and **speed**. Each of these counters is set to start counting from `0` again. This is a way to begin new counts without having to reset the motor.
## Example
See if the motor turns the same number of times for each of two count periods. Run the motor connected to port **A** twice for 10 seconds and compare the tacho counts.
```blocks
let tachoCount = 0;
motors.largeA.reset()
2018-02-19 16:35:08 +01:00
motors.largeA.run(50)
pause(10000)
tachoCount = motors.largeA.tacho()
motors.largeA.clearCounts()
2018-02-19 16:35:08 +01:00
motors.largeA.run(50)
pause(10000)
if (tachoCount == motors.largeA.tacho()) {
brick.showString("Motor turns equal.", 1)
} else {
brick.showString("Motor turns NOT equal.", 1)
}
motors.largeA.stop()
```
## See also
[tacho](/reference/motors/motor/tacho), [angle](/reference/motors/motor/angle),
[speed](/reference/motors/motor/speed), [reset](/reference/motors/motor/reset)