RobotC help

I am trying to display the value of a timer on the LCD, how do I do it :slight_smile: ?

The value of a timer can be accessed via code similar to the following:


int milliseconds = time1[T1];

Where T1 is the timer you’d like to obtain the value of. (This can be replaced with T2, T3, or T4.)

A string can be displayed on the LCD display via code similar to the following:

string s = "Hello World";
displayLCDString(0, 0, s);

Where the first parameter is the line number (0 for top, 1 for bottom), the second parameter is the row number, or the position on that line to begin writing from (0 means start at the far left), and the last parameter is the string you would like to display.

In order to write an integer to the LCD display, we can put it into a string. One way to do this is with code similar to the following:

int x = 3;
string s;
sprintf(s, "Value: %d", x);

Where the first parameter is the string we would like to put our variable(s) into, the second parameter is our “format string” which may contain regular text, as well as “format specifiers” which begin with a ‘%’ symbol (%d for integer, %f for float, %c for char, etc.) and represent where a value should be placed, and the last parameter(s) being the variables we would like to place into the string (given in the order in which they appear in the format string).

So, in order to print the value of a timer to the LCD display, we could do the following:

string s;
sprintf(s, "Timer1: %d", time1[T1]);
displayLCDString(0, 0, s);

Will


resetTimer

work to reset a timer? If it does, how do I use it.
I am trying to time a left, so the timer starts when the lift moves up, and stops when the lift is all the way down.

clearTimer is used to reset a timer, for instance:


clearTimer(T1);

clearTimer() resets a timer. If you need to use the time value right before it got cleared for something later, you need to store the time in a variable so that you can retrieve it later.

Heir is the code that I wrote:

task main()
{
	while(true)
	{
		while(vexRT[Btn5U] == 1)
		{
			resetTimer(T1);
		}
		while(vexRT[Btn5D] == 1)
		{
			string s;
			sprintf(s, "Timer1: %d",time1[T1]);
			displayLCDString(0,0,s);
		}
	}
}

If I run the program, it displays six numbers, I wont to have a program that will display the time that it takes to raise and lower a lift.