Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Question about NQC - (not quite c) - LEGO

Status
Not open for further replies.

toolman1981

Programmer
Jul 13, 2006
1
0
0
AU
Hi All,

I have a question about the language NQC, it is a specific language used to program LEGO robotics. I am not very familiar with it or c but thought I'd post here anyway. I have done a lot of programming, but it has all been with Fortran so far (I am a Mech engineer!!).

Ok all I want to do is write some code that executes a command only if two touch sensors are pushed the right amount of times in the right order.
e.g.
if sensor 1 is pushed twice, then if sensor 2 is pushed 3 times, then sensor 1 once, then sensor 2 twice then execute a set command.

How could I write this code in c??

Thanks for any help, Tim.
 
First of all you need to know how are your sensors communicate with your processor. Are they memory mapped, meaning they are assigned an address in the address space or they are assigned to a port. In the first case, you will initialize a pointer with the address and write and read to the sensor, or just read in your case, using pointer notation.
In the later, you will use INPORT() function if it supported by your compiler. Then you will need to write a tight interrupt handler to decrement a counter only when the right sequence of event happen. Of course you will need to set a time interval in which all these actions are valid otherwise, you clear your flag. Read some tutorials that comes with your system and start slower than that if you are new to embedded programming ( just an advice) you can also read

Programming Embedded Systems in C and C ++ (Paperback)
by Michael Barr. It will give you a good start. Good luck


Walid Magd (MCP)

The primary challenge of every software development team is to engineer the illusion of simplicity in the face of essential complexity.
-Grady Booch
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top