pxt-ev3/docs/reference/motors/motor/clear-counts.md
Galen Nickel 88c58b4e76 First set of 'motors' topics (#305)
* Start of 'motors' topics

* Draft the 'motor motion' side doc

* Add / update more topics

* Last blast of edits

* Capture some more edits

* Put in movement and steering details
2018-02-06 19:43:50 -08:00

1.0 KiB

clear Counts

Set all counters for the motor back to zero.

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.

let tachoCount = 0;
motors.largeA.reset()
motors.largeA.setSpeed(50)
loops.pause(10000)
tachoCount = motors.largeA.tacho()
motors.largeA.clearCounts()
motors.largeA.setSpeed(50)
loops.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, angle, speed, reset