skelly89 wrote:
Code: Select all
SetSensor(SENSOR_2, SENSOR_LIGHT);
The problem, I believe, is that you are using SENSOR_2, which can only be used in NXC as an alternative to calling Sensor(S2), instead of S2 which is a port number/name constant that must be used in any NXC API function that requires a port number. Hopefully the NXC Help documents and Guide PDF demonstrate and document this correctly. Some people use IN_n for port names. Those constants are intended for use in NBC and not NXC. The Sn constants are designed to be compatible with NQC code. Unlike NQC, however, which allowed you to use SENSOR_n constants for both naming a port and reading a sensor's value, NXC does not support that dual purpose for the SENSOR_n constants.
In summary:
1) use S1, S2, S3, or S4 in NXC code whenever you are required to pass a port value into an API function. Alternatively you can use a variable whose value is equal to one of these 4 constants.
2) Use Sensor(S1) or SENSOR_1 and so forth for any of the 4 ports so long as the attached sensor is an analog device (not an i2c device). If you look in the header file (NXCDefs.h) you will see #define SENSOR_1 Sensor(S1) so these two are equivalent.
3) SetSensor is not often used by people who did not come from the NQC world. It should work the same as SetSensorLight(S1) if you call it with the right parameters. SetSensor(S1, SENSOR_LIGHT);
I encourage you to read the Input module documentation in the NXC Help and NXC_Guide.
John Hansen