Page 4 of 7

Re: NXT PROBLEM

Posted: 20 Jun 2013, 21:16
by naneczek
You should have told me this from the start. I gave you the code, You didn't even look at it...

Re: NXT PROBLEM

Posted: 20 Jun 2013, 21:23
by HaWe
no, that's why I told you to post your whole code- what it is all about - in code tags.
I guess you'd better did it ;)

And now try to debug your code when you'll finally have your NXT again to work with! :ugeek:

Re: NXT PROBLEM

Posted: 20 Jun 2013, 21:27
by naneczek

Code: Select all

task main() {
ClearScreen();
int y;
int i;
int MyArray[100];

            SetSensorLowspeed(IN_4);

                  for (i=0;i<=100;i++) {
                  y= SensorUS(IN_4);
                  MyArray[i]=y

                  NumOut(0, 56, y, DRAW_OPT_CLEAR);

                   }

                  for (i=0;i<=100;++i) {
                  y=MyArray[i];
                  if (i==99) ClearScreen();

                  PointOut(i, y/4, DRAW_OPT_NORMAL);

                  }

          while (true);

}
Ok, now can you help me with this code? How to modify it to achieve desirable effects?

Re: NXT PROBLEM

Posted: 21 Jun 2013, 08:57
by HaWe
to make your code readable, please use:
for each { :
2 (or 3) extra spaces for indentation further to the right in the next line
for each } : 2 (or 3) spaces for indentation back to the left in the same line

Code: Select all


int main(int argc, char *argv[])
{
    ...
    while (x == y) {
        something();
        somethingelse();
 
        if (some_error) {
            /* the curly braces around this code block could be omitted */
            do_correct();
        } else
            continue_as_usual();
    }
 
    finalthing();
    ...
}

The K&R style, so named because it was used in Kernighan and Ritchie's book The C Programming Language, is commonly used in C. It is also used for C++, C#, and other curly brace programming languages.
have a look at this link: http://en.wikipedia.org/wiki/Indent_style#K.26R_style

Re: NXT PROBLEM

Posted: 22 Jun 2013, 09:23
by HaWe
ok,
your code still has not got the correct intendations, so you can't actuylly check what each block does, where it begins and where it ends.

That's important for debugging.

so let's improve your intendations:
e.g., from the line below "task main()...
until the line for(i...) all intendations must have the same level,
because it's the main body of the task main.

then the body of the for- loop must have the same level all over,
and so on.

So try once more, maybe you'll find first indications why your code won't work.

Re: NXT PROBLEM

Posted: 24 Jun 2013, 18:20
by naneczek

Code: Select all

task main()
{
    ClearScreen(); 
    int y;   
    int i;    
    SetSensorLowspeed(IN_4); 
   
    for (i=0;i<=100;++i)     
    {
        if (i>=100) {i=0; ClearScreen(); }    
        y = SensorUS(IN_4);    
        LineOut(i, y/4, DRAW_OPT_NORMAL);    
        NumOut(0,56, y, DRAW_OPT_CLEAR);    
    }
    while (true);    
}
Sth like this will do? I cannot check on any machine so I've got a request to check it. I want the measurements to be done in whole lines, not pixel by pixel. This whole line should be seen on the display, until the next measueremnt is done and when it is done it is depicted on the screen and so on.

Re: NXT PROBLEM

Posted: 26 Jun 2013, 07:33
by HaWe
now think about what you are doing:

Code: Select all

lines 1-4 in the main body: initialize.
 
for loop: 
- you poll a sensor value and assign it to y.
- you make a line out every time for each i
- you make a num out for every i

when the for loop is done once, then the program terminates in a perpetual wait state (while(true) ).
is this the way you want it?

no.

what you want is:
first get 100 values in a for loop (0-99) and assign it to an array,
then print the whole array in a for loop (0-99) on the screen,

and then you repeat all that endlessly.

Try it!

Re: NXT PROBLEM

Posted: 26 Jun 2013, 13:59
by naneczek
That's the case that I don't know how to do it. What should I put in the first array, how to do this loop, what kind of code should I implement? Could you help me out with this? or anyone? Or just show me the body of it with description.

Re: NXT PROBLEM

Posted: 26 Jun 2013, 15:14
by HaWe
I already showed you the principle some posts before. Just approach the problem logically!

Re: NXT PROBLEM

Posted: 26 Jun 2013, 16:16
by naneczek
Principle? I iwsh you would show me the code with description. So you won't help me?