Re: Scanning and displaying on NXT screen help!
You are definitely on the right track. Think about this in plain English though, and it might help you figure out the program flow:
1) Start a predetermined point (start point).
2) Move forward a set amount of distance.
3) Check the light sensor to see if it detects the line/object/shape
-If it does, the value stored in the array should be a 1 (or 2, 3, 4, 0; it's whatever number you want to designate a line detection. Generally, 1 is the easiest to use)
-If it doesn't, the value stored in the array should be a 0 (or a value different from the 'line detected' value; again, a 0 works nicely for this purpose)
4) If a line/object/shape is detected, write a pixel to the NXT screen. If it isn't, do not write a pixel.
5) Repeat steps 2-4 for the entire row.
6) Repeat steps 2-5 to scan each row in their entirety.
This is one of many ways to perform the scan, store, and display actions. Basically, the program will move -> scan -> check value -> store -> display, and will repeat each process until the end of the row. Then, the robot will have to turn or move down to the next row (depending on how the robot is set up) and repeat the move -> scan -> check -> store -> display process until the end of that row, and so on until it reaches the maximum number of rows.
Move - Recommend using the motor commands with encoders (nMotorEncoderTarget in particular) to ensure your robot moves only as far as it needs to.
Next Row - Once you reach certain the end of the row, you will need to move the robot to the next row; there are several ways to do this depending on the exact robot setup.
Scan - The SensorValue() command will return the value of whichever sensor is specified; you can then store this value in an array if you'd like and check the array values later, or check the value first and store an appropriate, corresponding (light or dark) value into the array.
Check Value - A simple if/else statement will suffice here; if the SensorValue is above a threshold, store a certain value into the array; if it's below the threshold, store a different value in the array.
Store - This is where it will get a bit tricky; since you are dealing with both rows and columns, you will probably need to do a two-dimensional array. For example, 5 rows with 10 columns would need a two dimensional array such as:
Display - You may want to do this at the end, once all of the values are collected. You will need to run through each array location individually and display either a pixel or no pixel depending on what value is stored in the array's location.
Tips: To run through all the values of an array, you'll usually want to utilize a 'for' loop
To run through a two-dimensional array, you simply need to nest the for loops inside one another:
Beyond that, it's a simple matter of tweaking the move commands to make sure you are getting a usable reading and displaying the object on the screen, which can be done by using the nxtSetPixel command
Hope this will help get you started, keep us posted on the progress!