ColorSensor and displayed int on the LCD screen

This is where you talk about the NXJ hardware related topics such as the brick, sensors, LEGO pieces, etc.

Moderators: 99jonathan, roger, imaqine

ColorSensor and displayed int on the LCD screen

Postby frederik » Fri Jan 25, 2008 7:17 pm

Today I received my new ColorSensor. While doing some tests for my new project (a Duplimate :?:) I found something strange happening.

A small part of the test program:

int color=0;

if (true) {
color = CS.getColorNumber();
if (color == 5) {
Sound.beep();
} // if
} // if
LCD.drawInt(color,3,6);
LCD.refresh();


the strange thing happening is the number on the LCD screen. It starts with a number between 0 and 17 but later on another digit appears and the displayed number is between 0 and 100. My "debugging-number 5 beep" tells me that variable "color" is 5 at that moment but the LCD screen shows 57 with a yellow paper in front of the sensor.

Any ideas what's happening? Thanx in advance! Frederik.
________
Ford Thames 300E Specifications
Last edited by frederik on Sun Feb 13, 2011 11:14 pm, edited 1 time in total.
frederik
New User
 
Posts: 23
Joined: Fri Dec 28, 2007 8:42 am

Postby kirkpthompson » Fri Jan 25, 2008 8:15 pm

Instead of
Code: Select all
LCD.drawInt(color,3,6);

try
Code: Select all
LCD.drawString(color + "   ",3,5);

The spaces at the end of the string (which is the color number converted to a string due to the concatenation operator +) will "wipe" out any previous displayed values if the number of digits in the color value get less. eg: "11" from "100"
User avatar
kirkpthompson
leJOS Team Member
 
Posts: 304
Joined: Wed Dec 05, 2007 1:27 am
Location: New Mexico, USA

Postby lawrie » Sat Jan 26, 2008 2:17 am

Or you can do:

Code: Select all
LCD.drawInt(color,2,3,6);


and the color value will always occupy two character positions on the screen.
lawrie
leJOS Team Member
 
Posts: 921
Joined: Mon Feb 05, 2007 1:27 pm

Thanks

Postby frederik » Sat Jan 26, 2008 9:01 am

Thank you, both workarounds solved the problem. The number on the screen is now an int between 0 and 17.
________
Vermont Dispensaries
frederik
New User
 
Posts: 23
Joined: Fri Dec 28, 2007 8:42 am


Return to NXJ Hardware

Who is online

Users browsing this forum: No registered users and 1 guest

more stuff