Getting Gyroscope to display on LCD - unofficial reply

Welcome to vexforum.

You posted this question in the RobotC text support Q&A section, most of us can not answer for you there so I’m posting the reply here. (perhaps one day they will make me an honorary RobotC team member :slight_smile: )

Anyway, the mistake in the code is that you are using the wrong parameter to the SensorValue function. Instead of

SensorValue( sensorGyro );

Use

SensorValue gyro ];

sensorGyro is the type of sensor, “gyro” was the name you gave to your gyro, you could have also used “in1” which is the name of analog input port 1.

There are a few other changes you could make to the code to improve efficiency. Here is a slightly revised version (post code between CODE tags, the # above the editing window)

I also added gyro initialization for you as that’s not very clear from the RobotC examples.

#pragma config(Sensor, in1, gyro, sensorGyro)

task main()
{
    int Angle;
 
    clearLCDLine(0);
    clearLCDLine(1);

    // Do this once
    bLCDBacklight = true;
    
    // So we need to reinitialize the gyro
    // each time the code runs
    SensorType gyro ] = sensorNone;
    wait1Msec(500);
    SensorType gyro ] = sensorGyro;
    wait1Msec(1000);
    
    while(true)
        {
        Angle = SensorValue gyro ];

        clearLCDLine(0);
        displayLCDPos(0,0);
        displayNextLCDString("GYR");
        displayLCDPos(0,4);
        displayNextLCDNumber(Angle);

        // Slow down the loop
        // no need to run so fast
        wait1Msec(25);
        }
}
1 Like

Thank you.

Like piniontwister, I would like to donate $75 to the jpearman challenge. If this is ok with you, please tell me the best way to forward the funds.

1 Like

I tried to reach you by email, but perhaps the forum doesn’t have a valid email address. Can you contact me at jbpearman_at_mac_dot_com if you are still interested in supporting this. Thanks.