Skip to content

Using the Sensor Struct

Jeffrey Shen edited this page Aug 1, 2017 · 10 revisions

This library provides the sensor structure for VEX sensors which makes monitoring their speed and values much more simple.

Setup

Define and initialize a sensor within your code like the example below:

sensor* sensor_name = initializeSensor(scaling_factor, sensor_port);

The asterisk is necessary, because that designates the sensor as a pointer.

sensor_port is what port that this sensor is bound to (i.e. in1, dgtl1, I2C_1). scaling_factor is a float that will be multiplied by the raw sensor value, so if you want to convert the raw value into something more meaningful (i.e. degrees), do that here.

Usage

Within any loop where you want to access this sensor's value, call updateSensorValue(sensor_name). This structure will not work without this function call. Then, you can access the speed and value of the sensor using sensor_name->speedand sensor_name->val, respectively. Value is equal to the raw sensor value times the scaling factor, and speed is in terms of units (as defined by the scaling factor) per second.

Clone this wiki locally