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

35 lines
976 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)
2018-03-28 18:04:28 +02:00
tachoCount = motors.largeA.angle()
motors.largeA.clearCounts()
2018-02-19 16:35:08 +01:00
motors.largeA.run(50)
pause(10000)
2018-03-28 18:04:28 +02:00
if (tachoCount == motors.largeA.angle()) {
brick.showString("Motor turns equal.", 1)
} else {
brick.showString("Motor turns NOT equal.", 1)
}
motors.largeA.stop()
```
## See also
2018-03-29 06:28:15 +02:00
[angle](/reference/motors/motor/angle),
[speed](/reference/motors/motor/speed), [reset](/reference/motors/motor/reset)