How do I read an NXT 2.0 color sensor in NXC?
PS: This is the 1999th post in the Software Forum!
NXC Color Sensor Help
NXC Color Sensor Help
51st Member Of MindBOARDS! (well, that's that the member's list says)
-
- Posts: 1818
- Joined: 02 Oct 2010, 02:19
- Location: Michigan USA
- Contact:
Re: NXC Color Sensor Help
This is one way
Code: Select all
task main()
{
while (true)
{
SetSensorColorFull(S1);
ColorSensorReadType csr;
csr.Port = S1;
SysColorSensorRead(csr);
if (csr.Result == NO_ERR)
{
NumOut(0, LCD_LINE1, csr.ColorValue);
}
}
}
Matt
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
Re: NXC Color Sensor Help
If you are wanting to just read the color number in full color mode then use SetSensorColorFull(port) to configure the port to work with the color sensor in full color mode and read the color value with SENSOR_n where n is S1..S4. If you want to use the color sensor as a regular light sensor then use SetSensorColorRed(port) and read the scaled value (0..100%) using SENSOR_n (i.e., SENSOR_1, SENSOR_2, SENSOR_3, or SENSOR_4). You could also use SetSensorColorGreen or SetSensorColorBlue if you want to experiment with other light colors instead of red. To read the raw values in these non-full-color modes you can use SensorRaw(port) or SensorValueRaw(port) to read the raw value. The NXC Programmer's Guide contains documentation for additional color sensor API functions that you can use in NXC.
http://bricxcc.sourceforge.net/nbc/nxcd ... index.html
Drill down in the navigation tree to Modules\NXT Firmware Modules\Input module\Input module functions\.
John Hansen
http://bricxcc.sourceforge.net/nbc/nxcd ... index.html
Drill down in the navigation tree to Modules\NXT Firmware Modules\Input module\Input module functions\.
John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
http://bricxcc.sourceforge.net/
Re: NXC Color Sensor Help
I have tried SetSensorColorFull(S#), but I keep getting errors. For example, I get the following errors with mattallen37's code:
FYI, In BricxCC if I go to Preferences/Compiler/NBC&NBC and click "Version" I get 1.0.1.35. (I think that's my problem) I cannot upgrade at the moment. All I need to do is tell the difference between black and white. Is there still anything I can do?
Code: Select all
Line 5: Undefined Indentifer SetSensorColorFull
Line 5: "=" expected
Line 5: ";" expected
Line 6: Undefined Identifier ColorSensorReadType
Line 6: "=" expected
Line 7: Math Factor expected
Line 7: Undefined Identifier ColorSensorReadType
Line 8: Undefined Identifier SysColorSensorRead
Line 8: "=" expected
Line 8: Undefined Identifier csr
Line 8: ";" expected
Line 9: Undefined Identifier csr.result
51st Member Of MindBOARDS! (well, that's that the member's list says)
-
- Posts: 1818
- Joined: 02 Oct 2010, 02:19
- Location: Michigan USA
- Contact:
Re: NXC Color Sensor Help
Yes, try upgrading. Also, you may need the enhanced firmware for the NXT.
Matt
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
Who is online
Users browsing this forum: No registered users and 2 guests