Repository navigation
6. API: Sensor Function
These are the functions to communicate with the sensors.
Turn on/off the sensor LED.
Function Prototype:
EM_ERROR eSensorSetLed( unsigned char ucId,
EM_MODEL eModuleType,
unsigned char ucLedValue );
Parameters:
- ucId - Sensor ID.
- eModuleType - Sensor type.
-
ucLedValue - Sensor LED value.
~ 0 - Off
~ 1 - On
~ 2 - Trigger
Return:
Example:
// Turn on the IR sensor LED.
eSensorSetLed(200, EM_MODEL_IR, 1);
Turn on/off and set the colour of the Head LED.
Function Prototype:
EM_ERROR eHeadSetLed( unsigned char ucId,
unsigned char ucRgb,
unsigned char ucLeftRight );
Parameters:
- ucId - Sensor ID.
- ucRgb - RGB value for the LED (RRRGGGBB).
-
ucLeftRight - Turn on/off left and right LED individually.
~ Bit 0 - Right
~ Bit 1 - Left
Return:
Example:
// Set the colour of head LED to red.
eHeadSetLed(100, 0b11100000, 0b11);
Set the red colour LED of the head module.
Function Prototype:
EM_ERROR eHeadSetRed(unsigned char ucId, unsigned char ucRedValue);
Parameters:
- ucId - Sensor ID.
- ucRedValue - Red LED value (3 bits).
Return:
Example:
// Set the colour of head LED to red.
eHeadSetRed(100, 0b111);
Set the green colour LED of the head module.
Function Prototype:
EM_ERROR eHeadSetGreen(unsigned char ucId, unsigned char ucGreenValue);
Parameters:
- ucId - Sensor ID.
- ucGreenValue - Green LED value (3 bits).
Return:
Example:
// Set the colour of head LED to green.
eHeadSetGreen(100, 0b111);
Set the blue colour LED of the head module.
Function Prototype:
EM_ERROR eHeadSetBlue(unsigned char ucId, unsigned char ucBlueValue);
Parameters:
- ucId - Sensor ID.
- ucBlueValue - Blue LED value (2 bits).
Return:
Example:
// Set the colour of head LED to blue.
eHeadSetBlue(100, 0b11);
Get the IR sensor value on head module.
Function Prototype:
EM_ERROR eHeadGetIrValue(unsigned char ucId, unsigned char *pucValue);
Parameters:
- ucId - Sensor ID.
- pucValue - Buffer to return the value.
Return:
Example:
// Read the IR sensor value from head module.
unsigned char ucHeadIrValue;
eHeadGetIrValue(100, &ucHeadIrValue);
Get the microphone value on head module.
Function Prototype:
EM_ERROR eHeadGetMicValue(unsigned char ucId, unsigned char *pucValue);
Parameters:
- ucId - Sensor ID.
- pucValue - Buffer to return the value.
Return:
Example:
// Read the microphone value from head module.
unsigned char ucMicValue;
eHeadGetMicValue(100, &ucMicValue);
Get the infrared sensor value.
Function Prototype:
EM_ERROR eInfraredSensorGetValue(unsigned char ucId, unsigned char *pucValue);
Parameters:
- ucId - Sensor ID.
- pucValue - Buffer to return the value.
Return:
Example:
// Read the value from infrared sensor.
unsigned char ucValue;
eInfraredSensorGetValue(100, &ucValue);
Get the ultrasonic sensor value.
Function Prototype:
EM_ERROR eUltrasonicSensorGetValue(unsigned char ucId, unsigned short *pusValue);
Parameters:
- ucId - Sensor ID.
- pusValue - Buffer to return the value.
Return:
Example:
// Read the value from ultrasonic sensor.
unsigned short usValue;
eUltrasonicSensorGetValue(100, &usValue);
Get the tactile sensor value.
Function Prototype:
EM_ERROR eTactileSensorGetValue(unsigned char ucId, unsigned char *pucValue);
Parameters:
- ucId - Sensor ID.
-
pucValue - Buffer to return the value.
~ 0 - Released
~ 1 - Pressed
Return:
Example:
// Read the value from tactile sensor.
unsigned char ucValue;
eTactileSensorGetValue(100, &ucValue);
Get the analog value from line sensor.
Function Prototype:
EM_ERROR eLineSensorGetAnalog( unsigned char ucId,
unsigned char *pucS1,
unsigned char *pucS2,
unsigned char *pucS3,
unsigned char *pucS4 );
Parameters:
- ucId - Sensor ID.
- pucS1 - Buffer to return the value for sensor 1.
- pucS2 - Buffer to return the value for sensor 2.
- pucS3 - Buffer to return the value for sensor 3.
- pucS4 - Buffer to return the value for sensor 4.
Return:
Example:
// Read the analog value for each sensor from line sensor.
unsigned char ucValue1;
unsigned char ucValue2;
unsigned char ucValue3;
unsigned char ucValue4;
eLineSensorGetAnalog(100, &ucValue1, &ucValue2, &ucValue3, &ucValue4);
Get the digital value from line sensor.
Function Prototype:
EM_ERROR eLineSensorGetDigital(unsigned char ucId, unsigned char *pucValue);
Parameters:
- ucId - Sensor ID.
-
pucValue - Buffer to return the value.
~ Bit 0 - S1
~ Bit 1 - S2
~ Bit 2 - S3
~ Bit 3 - S4
Return:
Example:
// Read the digital value for each sensor from line sensor.
unsigned char ucValue;
eLineSensorGetDigital(100, &ucValue);
Get the line sensor setting whether to detect light or dark line.
Function Prototype:
EM_ERROR eLineSensorGetDarkLight(unsigned char ucId, unsigned char *pucValue);
Parameters:
- ucId - Sensor ID.
-
pucValue - Buffer to return the value.
~ 0 = Dark on.
~ 1 = Light on.
Return:
Example:
// Check whether the line sensor is set to detect dark or light line.
unsigned char ucValue;
eLineSensorGetDarkLight(100, &ucValue);
Set the line sensor to detect light or dark line.
Function Prototype:
EM_ERROR eLineSensorSetDarkLight(unsigned char ucId, unsigned char ucDarkLight);
Parameters:
- ucId - Sensor ID.
-
ucDarkLight - Light on or dark on.
~ 0 = Dark on.
~ 1 = Light on.
Return:
Example:
// Set the line sensor to detect dark line.
eLineSensorSetDarkLight(100, 0);
Start or stop the auto calibration for line sensor.
Function Prototype:
EM_ERROR eLineSensorSetAutoCal(unsigned char ucId, unsigned char ucValue);
Parameters:
- ucId - Sensor ID.
-
ucValue - Start or stop the auto calibration.
~ 0 = Stop
~ 1 = Start
Return:
Example:
// Start the auto-calibration process.
eLineSensorSetAutoCal(100, 1);
Get the RGB value from colour sensor.
Function Prototype:
EM_ERROR eColourSensorGetRgb( unsigned char ucId,
unsigned char *pucRed,
unsigned char *pucGreen,
unsigned char *pucBlue );
Parameters:
- ucId - Sensor ID.
- pucRed - Buffer to return the red value.
- pucGreen - Buffer to return the green value.
- pucBlue - Buffer to return the blue value.
Return:
Example:
// Get the RGB value from colour sensor.
unsigned char ucRed;
unsigned char ucGreen;
unsigned char ucBlue;
eColourSensorGetRgb(100, &ucRed, &ucGreen, &ucBlue);
Get the reflected brightness value from colour sensor.
Function Prototype:
EM_ERROR eColourSensorGetBrightness(unsigned char ucId, unsigned char *pucValue);
Parameters:
- ucId - Sensor ID.
- pucValue - Buffer to return red value.
Return:
Example:
// Get the reflected brightness value from colour sensor.
unsigned char ucValue;
eColourSensorGetBrightness(100, &ucValue);
Get the ambient light value from colour sensor.
Function Prototype:
EM_ERROR eColourSensorGetAmbient(unsigned char ucId, unsigned char *pucValue);
Parameters:
- ucId - Sensor ID.
- pucValue - Buffer to return red value.
Return:
Example:
// Get the ambient light value from colour sensor.
unsigned char ucValue;
eColourSensorGetAmbient(100, &ucValue);
Get the detected colour from colour sensor.
Function Prototype:
EM_ERROR eColourSensorGetColour(unsigned char ucId, CL_SENSOR_COLOUR *peColour);
Parameters:
- ucId - Sensor ID.
- peColour - Buffer to return the detected colour.
Return:
Example:
// Get the detected from colour sensor.
CL_SENSOR_COLOUR eColour;
eColourSensorGetColour(100, &eColour);