.. _object_Counter: :index:`Counter` ---------------- Description *********** The Counter object provides a basic counter functionality. It increments the :ref:`value ` property periodically depending on the configured :ref:`interval `. It's also possible to count backwards by setting the :ref:`increment ` property to a negative value and optionally setting the :ref:`startValue ` property. :**› Inherits**: :ref:`Object ` Overview ******** Properties ++++++++++ .. hlist:: :columns: 1 * :ref:`increment ` * :ref:`interval ` * :ref:`running ` * :ref:`startValue ` * :ref:`value ` * :ref:`Object.objectId ` * :ref:`Object.parent ` Methods +++++++ .. hlist:: :columns: 1 * :ref:`reset() ` * :ref:`Object.deserializeProperties() ` * :ref:`Object.fromJson() ` * :ref:`Object.serializeProperties() ` * :ref:`Object.toJson() ` Signals +++++++ .. hlist:: :columns: 1 * :ref:`Object.completed() ` Properties ********** .. _property_Counter_increment: .. _signal_Counter_incrementChanged: .. index:: single: increment increment +++++++++ This property holds the number by which :ref:`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 .. _property_Counter_interval: .. _signal_Counter_intervalChanged: .. index:: single: interval 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 :ref:`running ` has to be ``true``. :**› Type**: SignedInteger :**› Default**: ``1000`` :**› Signal**: intervalChanged() :**› Attributes**: Writable .. _property_Counter_running: .. _signal_Counter_runningChanged: .. index:: single: running running +++++++ This property holds whether the counter is running. Changing this property does not reset the counter's :ref:`value `. :**› Type**: Boolean :**› Default**: ``true`` :**› Signal**: runningChanged() :**› Attributes**: Writable .. _property_Counter_startValue: .. _signal_Counter_startValueChanged: .. index:: single: startValue startValue ++++++++++ This property holds the start value which the :ref:`value ` property is initialized on start and every :ref:`reset() `. Changing this value has no effect on running counters until :ref:`reset() ` is called. :**› Type**: SignedInteger :**› Default**: ``0`` :**› Signal**: startValueChanged() :**› Attributes**: Writable .. _property_Counter_value: .. _signal_Counter_valueChanged: .. index:: single: value value +++++ This property holds the current value of the counter. On initial start and on every :ref:`reset() ` the property is set to :ref:`startValue `. It is incremented by :ref:`increment ` every :ref:`interval ` milliseconds. :**› Type**: SignedBigInteger :**› Default**: ``0`` :**› Signal**: valueChanged() :**› Attributes**: Readonly Methods ******* .. _method_Counter_reset: .. index:: single: reset reset() +++++++ This method resets the counter by setting the :ref:`value ` back to :ref:`startValue `. It can be called on both stopped and running counters. Running counters will continue to run after being reset. .. _example_Counter: Example ******* .. code-block:: qml 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. ) ) } }