10-14-22 add image for creating new timer variable
@ -31,12 +31,20 @@ In general you will create your own timer, then use pre-made commands or <u>meth
|
||||
|
||||
## Create a Timer
|
||||
|
||||
The first step is to create a new timer <u>object</u>. Here we call the new timer object "myTimer". You could think of it as "My New Stopwatch" (although Blocks timers don't actually stop).
|
||||
The first step is to create a new Variable, called "myTimer" (or any other name that suits its purpose in your OpMode).
|
||||
|
||||
> **Programming note:** In Java, an Object is an <u>instance</u> or example of a Class. FTC Blocks provides a class called ElapsedTime. A class can contain variables and methods (commands). Your new timer is an instance of that Java class, inheriting its characteristics.
|
||||
<p align="center">[[/images/Timers-in-FTC-Blocks/0115-create-variable.png|]]<p>
|
||||
|
||||
But "myTimer" will not be an ordinary variable that stores a number, or text, or Boolean value.
|
||||
|
||||
From the Variables menu, and from the ElapsedTime menu, create this Blocks command:
|
||||
|
||||
<p align="center">[[/images/Timers-in-FTC-Blocks/0120-set-myTimer.png|]]<p>
|
||||
|
||||
Now "myTimer" is a timer <u>object</u>, which you can think of as "My New Stopwatch" (although Blocks timers don't actually stop).
|
||||
|
||||
> **Programming note:** In Java, an Object is an <u>instance</u> or example of a Class. FTC Blocks provides a class called ElapsedTime. A class can contain variables and methods (commands). Your new timer is an instance of that Java class, inheriting its characteristics.
|
||||
|
||||
This is not the usual Blocks "Set" command. Instead of assigning a number to a variable, this Block creates or <u>instantiates</u> a new object called myTimer. The Java keyword <u>new</u> causes myTimer to be created as an instance of the class ElapsedTime.
|
||||
|
||||
The default unit of reporting time is Seconds, for a timer created with the simple Block shown above. An option for Milliseconds is discussed far below.
|
||||
@ -288,3 +296,8 @@ This tutorial described basic use of Timers in Blocks programming. Timers also
|
||||
<br><i>Questions, comments and corrections to: westsiderobotics@verizon.net</i>
|
||||
<br>
|
||||
<br>
|
||||
|
||||
<!--
|
||||
This text does not appear at the published wiki.
|
||||
|
||||
-->
|
Reference in New Issue
Block a user