for(unsigned char i=20;i<100;i++) {mx=i; delay(5);} <-- this works
for(unsigned int i=20;i<100;i++) {mx=i; delay(5);} <-- this does not work
why ?
for(unsigned char i=20;i<100;i++) {mx=i; delay(5);} <-- this works
for(unsigned int i=20;i<100;i++) {mx=i; delay(5);} <-- this does not work
why ?
How can you tell whether it works or not?
Pete
the incremention of the the variable is displayed via Serial . the second case . the system freezes and does nothing
you may be running out of memory...
Can you post the entire code? Remember that the variable 'i' it's only valid inside the block created by the brackets '{ }'.
it's the arduino mega . 8k of sram (thank you CrossRoads) , that would be impossible .
the parts of the code that does deal with that variable are these
volatile unsigned short mx,my,pmx,pmy;
while(1)
{
for(unsigned char i=20;i<100;i++) {mx=i; my=i; _delay_ms(10);}
}
ISR (TIMER1_COMPA_vect)
{
output_pointer(pmx,pmy,mouse_ram);
read_to_ram(mx,my);
output_pointer(mx,my,mouse,1);
pmx=mx; pmy=my;
}
Does this code work?
for(unsigned int i=20;i<100;i++) {mx= (unsigned char) i; delay(5);}
4k of sram , that would be impossible .
That reminds me of Bill Gate's famous "640K of memory" quote.
Small correction...
That reminds me of Bill Gate's infamous "640K of memory" quote.
Mega has 8K of SRAM, not 4K.
Might still be a bit short.
ok .
lusiva this -> for(unsigned int i=20;i<100;i++) {mx= (unsigned char) i; delay(5);} does not work
this works though -> for(unsigned char i=20;i<100;i++) {mx= (unsigned int) i; delay(5);} <- the reverse works .
this also works : for(unsigned char i=20;i<100;i++) {mx=i+500; delay(5);}
volatile unsigned short mx,my,pmx,pmy;
So why on earth would you use an int variable as the loop index and assign the int value to these?
Was there some part of "ALL OF YOUR CODE" that is beyond your comprehension?
dude it's very long . the problem is clear man . the for loop does not accept a variable larger than a single byte . i cant even understand that
dude it's very long . the problem is clear man . the for loop does not accept a variable larger than a single byte . i cant even understand that
the incremention of the the variable is displayed via Serial .
I have seen no code in this thread that does that. Would you care to share it with us as requested ?
I do, however, see an infinite loop
while(1)
{
for(unsigned char i=20;i<100;i++) {mx=i; my=i; _delay_ms(10);}
}
the for loop does not accept a variable larger than a single byte . i cant even understand that
Nonsense. You can even use a long long which is 8 bytes.
dude it's very long . the problem is clear man .
That your have boatloads of code MAY be the problem. The problem is NOT clear. You have provided NO proof that the for loop does not do anything. NONE!
amine2:
the problem is clear man
If it was clear to you, you would already have solved the problem.
It is NOT clear to us because you are wasting everyone's time by refusing to post the complete program.
...R
i solved the problem . thank you though .
solution :
unsigned short i=10;
while(i<300) {mx=i; i++; delay(5); }
this works while the for loop does not , for this part of the code .
You can't seriously leave it there. You are obviously doing something odd because for loops do work. I still don't understand how you know that the for loop does not work. What is the mx variable in your while loop used for ?
Try
for (int i = 10; i < 300; i++)
{
delay(5);
}
hi . when i use a for loop witch an "unsigned shar" counter , it counts fine .
when i use a bigger counter though ("short" "unsigned short" "unsigned int") it counts to a small value then stops for no possible reason . this is really unusual .
the "while" loop though works