Heey I'm doing a easy calculation assignment for my study. But I do not understand why I can not put my code in the void loop part. If i do that the code is not really working. If i use it like it's now it works fine. How do i fix it.
void setup()
{
Serial.begin(9600);
int uur;
long int uitkomst = 1000;
do
{
uur = uur + 5;
uitkomst = uitkomst * 2 ;
Serial.print(uur);
Serial.print(" ");
Serial.println(uitkomst);
} while (uitkomst < 1000000);
Serial.print("de uitkomst is");
Serial.print(" ");
Serial.print( uur );
}
void loop()
{
}
In what way is it not really working?
Sooooo.... You have code that IS working, and you have code that is NOT working, and you post the code that IS working, and ask us why the code that is NOT working it NOT working?
Does that make sense to you?
Regards,
Ray L.
what i mean to say is when i copy paste this exact code in the void loop part, it is not working anymore. that i think is a bit strange. so maybe one of you can tell me why?
flobv12:
what i mean to say is when i copy paste this exact code in the void loop part, it is not working anymore. that i think is a bit strange. so maybe one of you can tell me why?
People make many copy/paste any other mistakes. We do not need to see the code that works. We need to see the code that does not work. Please copy and paste the code directly from the IDE that does not work and post it here, or we cannot help you.
'setup()' and 'loop()' exist in a universe something like -
int main()
{
... SOME CODE ...
setup();
for ( ; true ; )
{
loop();
}
... POSSIBLY SOME MORE CODE ...
}
Can you now see what might be going wrong???
lloyddean:
'setup()' and 'loop()' exist in a universe something like -
int main()
{
... SOME CODE ...
setup();
for ( ; true ; )
{
loop();
}
... POSSIBLY SOME MORE CODE ...
}
Can you now see what might be going wrong???
which should be fine for him, depending on how he moved his code, which he has not yet shown us. It would just do it more than once.
arduinodlb:
which should be fine for him, depending on how he moved his code, which he has not yet shown us. It would just do it more than once.
Ye, I know but since he hasn't yet replied to my first post we don't know what he considers as his problem!
this is the code that does not work.
void setup()
{
Serial.begin(9600);
}
void loop()
{
int uur;
long int uitkomst = 1000;
do
{
uur = uur + 5;
uitkomst = uitkomst * 2 ;
Serial.print(uur);
Serial.print(" ");
Serial.println(uitkomst);
} while (uitkomst < 1000000);
Serial.print("de uitkomst is");
Serial.print(" ");
Serial.print( uur );
}
change this:
int uur;
to this:
int uur = 0;
you probably also want to put a delay inside your while loop. Maybe:
...
delay(200);
} while (uitkomst < 1000000);
Also, when you say it does not work, what happens? Anything? What is different to what you expect to happen?