# Timer

## Properties

You can set:

* The **Name** of the Timer
* The **Interval** of the Timer, in seconds or milliseconds
* Whether or not the Timer should **Count Up**
* Whether the Timer should **Loop**, ie. if the Timer should reset itself once it fires
* Whether the Timer is **Enabled** (this can be changed with blocks)

## Event Blocks

### When Timer Fires

![](https://689802330-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAn5scXl2uqUJUOqkJo%2F-MJWWgPcZZc65tAJb8I1%2F-MJWXuWTTmlaF7gFpJkN%2Fwhentimerfires.png?alt=media\&token=5c8dd648-a158-4283-aa69-1f9d1cd9438f)

Set something to happen when the Timer fires.

## Function Blocks

### Start Timer

![](https://689802330-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAn5scXl2uqUJUOqkJo%2F-MJWWgPcZZc65tAJb8I1%2F-MJWY0AtrWSOHqGwDlgC%2Fnewtimerblocks%20start.png?alt=media\&token=b674fec1-fdf4-4dc1-9cd8-a67258315ec3)

Starts the Timer.

### Stop Timer

![](https://689802330-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAn5scXl2uqUJUOqkJo%2F-MJWWgPcZZc65tAJb8I1%2F-MJWY31N1sxVfhd6gaJX%2Fnewtimerblocks%20stop.png?alt=media\&token=c68194ca-60c5-4643-ad8e-0665e6e0a9ca)

Stops the Timer.

## Properties Blocks

### Get Time

#### Get time in seconds

![](https://689802330-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAn5scXl2uqUJUOqkJo%2F-MJWWgPcZZc65tAJb8I1%2F-MJWY8EIH16sZ174IKX9%2Fnewtimerblocks%20get%20time%20seconds.png?alt=media\&token=21b4513a-5ff7-4d49-8e1f-c1eb0374bb5a)

If `Count Up` is `false`, returns remaining time from the Timer's interval in seconds.

If `Count Up` is `true`, returns elapsed time from the Timer's interval in seconds.

#### Get time in milliseconds

![](https://689802330-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAn5scXl2uqUJUOqkJo%2F-MJWWgPcZZc65tAJb8I1%2F-MJWYBigJ-TkVZSn--Gk%2Fnewtimerblocks%20get%20time%20milliseconds.png?alt=media\&token=eab2279f-d53b-4067-bef2-10497cdc04c0)

If `Count Up` is `false`, returns remaining time from the Timer's interval in milliseconds.

If `Count Up` is `true`, returns elapsed time from the Timer's interval in milliseconds.

### Interval

#### Set Interval

![](https://689802330-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAn5scXl2uqUJUOqkJo%2F-MJWWgPcZZc65tAJb8I1%2F-MJWYEI8x8NYt_Q-gwQ2%2Fnewtimerblocks%20set%20interval.png?alt=media\&token=5bf59f81-fe99-4491-8647-e678dd886424)

Set interval of Timer in milliseconds.

#### Get Interval of Timer

![](https://689802330-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAn5scXl2uqUJUOqkJo%2F-MJWWgPcZZc65tAJb8I1%2F-MJWYt5mDBdrvK3oxsTX%2Fimage.png?alt=media\&token=acb6a0af-4545-4483-b01d-df4cd2b19e9b)

Returns interval of Timer in milliseconds.

### Count Up

#### Set Count Up

![](https://689802330-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAn5scXl2uqUJUOqkJo%2F-MJWWgPcZZc65tAJb8I1%2F-MJWYPdXHu7MsilTLB1d%2Fnewtimerblocks%20set%20countup.png?alt=media\&token=003b2fb9-6167-4e47-8957-dd7d13136eb4)

Set whether Count Up is enabled for this Timer.

#### Get Count Up

![](https://689802330-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAn5scXl2uqUJUOqkJo%2F-MJWWgPcZZc65tAJb8I1%2F-MJWYSn1v_ccfTv-AA0n%2Fnewtimerblocks%20get%20countup.png?alt=media\&token=eb2bf8a7-4e03-4d95-b6ec-721f992cb41c)

Returns `true` or `false` value for whether Count Up is enabled for this Timer.

### Loops

#### Set Loops

![](https://689802330-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAn5scXl2uqUJUOqkJo%2F-MJWWgPcZZc65tAJb8I1%2F-MJWYVdL_vfu3swJ6a2B%2Fnewtimerblocks%20setloops.png?alt=media\&token=31be2556-da1b-4fbd-a4da-4403990669da)

If `Loops = true`, the timer will reset itself after it fires. If your interval is 10 seconds, the Timer will fire every 10 seconds.

If `Loops = false`, the timer will finish its current interval if it is in the middle of one, and will no longer fire. If your interval is 10s, the timer will finish its current 10 second interval, fire, and then stop.

#### Get Loops

![](https://689802330-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAn5scXl2uqUJUOqkJo%2F-MJWWgPcZZc65tAJb8I1%2F-MJWYZCiFH3c4-mutudQ%2Fnewtimerblocks%20get%20loops.png?alt=media\&token=2fac0e71-387a-4c23-bcf6-d4b3603339e5)

Returns `true` or `false` value for whether Loops is enabled for this Timer.

### Enabled

#### Set Enabled

![](https://689802330-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAn5scXl2uqUJUOqkJo%2F-MJWWgPcZZc65tAJb8I1%2F-MJWYbK0vUDBJC1NUe5l%2Fnewtimerblocks%20set%20enabled.png?alt=media\&token=e303a040-b003-4235-a4b7-61f5f47b4776)

Set whether the Timer is enabled.

#### Get Enabled

![](https://689802330-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAn5scXl2uqUJUOqkJo%2F-MJWWgPcZZc65tAJb8I1%2F-MJWYhCqq5Wtofj1m6zJ%2Fnewtimerblocks%20get%20enabled.png?alt=media\&token=3e97897c-bb53-4c3f-9f44-86b8d1e4a665)

Returns `true` or `false` value for whether this Timer is enabled.

### Example 1: **How to Build a Stopwatch** <a href="#example-1-how-to-build-a-stopwatch" id="example-1-how-to-build-a-stopwatch"></a>

1. Start by creating a variable and set its value to 0 (this will keep track of the time).
2. Add a timer to your project.
3. Add a button that will start and pause the stopwatch.
4. Inside the "when button click" block, add a condition: if the timer is running, pause the stopwatch; if it's not, start it.
5. Set the timer interval to 1 second/1000 Milliseconds and enable looping so it keeps running.
6. Add a label to display the elapsed time in seconds.
7. Use the "when timer fires" block to increase the variable by 1 every second and update the label with the new value.

<figure><img src="https://689802330-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUe3rgJfvQYLrpDR1HfWv%2Fuploads%2F4Qx3FO5qBzoVuKsO6o4h%2Fimage%20-%202024-10-24T170024.389.png?alt=media&#x26;token=341e227b-c1a9-4cbc-88e5-9fccf84836c5" alt=""><figcaption></figcaption></figure>

### Example 2: **How to Build a Timer** <a href="#example-2-how-to-build-a-timer" id="example-2-how-to-build-a-timer"></a>

* Start by creating a variable and set its value to 5000 to count five minutes.
* Add a timer to your project.
* Add a button that will start and pause the Timer.
* Inside the "when button click" block, add a condition: if the timer is running, pause the Timer; if it's not, start it.
* Set the timer interval to 1 second/1000 Milliseconds and enable looping so it keeps running.
* Add a label to display the running time in seconds.
* Use the "when timer fires" block to decrease the variable by 1 every second and update the label with the new value if the variable is greater than zero.

<figure><img src="https://689802330-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUe3rgJfvQYLrpDR1HfWv%2Fuploads%2F9SHb5tyjarYK59wpN2mu%2Fimage%20-%202024-10-24T165847.218.png?alt=media&#x26;token=6936f8a6-7a34-4f76-8532-40d9c4ecc54b" alt=""><figcaption></figcaption></figure>
