NXT PROBLEM
Re: NXT PROBLEM
You should have told me this from the start. I gave you the code, You didn't even look at it...
Re: NXT PROBLEM
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!
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!
Re: NXT PROBLEM
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);
}
Last edited by naneczek on 22 Jun 2013, 06:52, edited 3 times in total.
Re: NXT PROBLEM
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
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();
...
}
have a look at this link: http://en.wikipedia.org/wiki/Indent_style#K.26R_styleThe 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.
Re: NXT PROBLEM
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.
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
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);
}
Re: NXT PROBLEM
now think about what you are doing:
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!
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) ).
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
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
I already showed you the principle some posts before. Just approach the problem logically!
Re: NXT PROBLEM
Principle? I iwsh you would show me the code with description. So you won't help me?
Who is online
Users browsing this forum: No registered users and 1 guest