hi, i am a beginner in programming. i have a problem and any help will be very much appreciated.i am trying to program a color sensor where a variable is incremented whenever it detects the same color.(example is if it detects a green, x will be incremented by one.)

but i'm not getting the output that i want.whenever it sees a green, x is always incrementing continuously. i want it to only increase by 1 one at a time in every detection.(i apologize for my grammar :] )can anyone help me with this. thanks a lot.

jamekz~

Sun Mar 04, 2012 1:34 am

MHTS

Guru

Joined: Sun Nov 15, 2009 5:46 amPosts: 1523

Re: coding problem.

It is because the CPU is running really fast. It was detecting the same color object over and over again continuously. If you want to count color objects, you need to detect transitions instead. For example, you only count it when you previously don't see that color, then you see the color. Once you see the color and incremented one, you don't count until the color changed to something else before you detect that color again.

thanks for the reply. it now worked just as expected. now I am having fun playing/programming with my nxt.

I'm kinda curious, is it possible to send the value of the color to a mobile?..I kinda want to experiment my lego and do a bunch of things.if it's possible, can I program it using robotc?..I read some of the topics here but all I get is controlling the nxt from a mobile.how about doing the opposite which is to send a data to a mobile from the nxt.

thanks for the advice. this will be a great start for my career.

jamekz~

Mon Mar 05, 2012 9:51 am

MHTS

Guru

Joined: Sun Nov 15, 2009 5:46 amPosts: 1523

Re: coding problem.

In theory, you can do this using Bluetooth communication. I've not done any Bluetooth programming so can't help you there but there are a lot of discussing threads on similar topics. You may want to search for them.

Mon Mar 05, 2012 2:10 pm

RoboDesigners

Novice

Joined: Sat Jul 10, 2010 3:06 pmPosts: 86Location: Roanoke, VA

Re: coding problem.

jamekz wrote:

I'm kinda curious, is it possible to send the value of the color to a mobile?..I kinda want to experiment my lego and do a bunch of things.if it's possible, can I program it using robotc?..I read some of the topics here but all I get is controlling the nxt from a mobile.how about doing the opposite which is to send a data to a mobile from the nxt.

Bluetooth would be the way to go. However, you will need to find or create an app for your phone that will display the Bluetooth message.//Andrew

Who is online

Users browsing this forum: No registered users and 2 guests

You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum