Counter
Description
The Counter object provides a basic counter functionality. It increments the value property periodically depending on the configured interval. It’s also possible to count backwards by setting the increment property to a negative value and optionally setting the startValue property.
- › Inherits:
Overview
Properties
Methods
Signals
Properties
increment
This property holds the number by which value is incremented each period. It can be both positive and negative. Negative values will make the counter count backwards.
- › Type:
SignedInteger
- › Default:
1- › Signal:
incrementChanged()
- › Attributes:
Writable, Optional
interval
This property holds the counter interval in milliseconds. The interval has to be greater than 0 in order to make the counter work properly. Additionally running has to be true.
- › Type:
SignedInteger
- › Default:
1000- › Signal:
intervalChanged()
- › Attributes:
Writable
running
This property holds whether the counter is running. Changing this property does not reset the counter’s value.
- › Type:
Boolean
- › Default:
true- › Signal:
runningChanged()
- › Attributes:
Writable
startValue
This property holds the start value which the value property is initialized on start and every reset(). Changing this value has no effect on running counters until reset() is called.
- › Type:
SignedInteger
- › Default:
0- › Signal:
startValueChanged()
- › Attributes:
Writable
value
This property holds the current value of the counter. On initial start and on every reset() the property is set to startValue. It is incremented by increment every interval milliseconds.
- › Type:
SignedBigInteger
- › Default:
0- › Signal:
valueChanged()
- › Attributes:
Readonly
Methods
reset()
This method resets the counter by setting the value back to startValue. It can be called on both stopped and running counters. Running counters will continue to run after being reset.
Example
import InCore.Foundation 2.5
import InCore.IO 2.5
Application {
DigitalIO {
id: input
direction: DigitalIO.Input
index: DigitalIO.IO1
}
Counter {
id: secCounter
interval: 100 //10 per second
running: input.value
startValue: 0 //default
onValueChanged: console.log( ( "input were %1 seconds on" ).arg( input.value / 10. ) )
}
}