Society of Robots - Robot Forum
Software => Software => Topic started by: GrooveHolmes on December 04, 2010, 10:36:56 PM
-
TICK_COUNT appControl(LOOP_COUNT loopCount, TICK_COUNT loopstart){
if(button_pressed()){
rprintf("Pressed\n");
}
return 200000; //1,000,000 = 1 second
}
Seems timed with the return value of the appControl() function.
TICK_COUNT appControl(LOOP_COUNT loopCount, TICK_COUNT loopstart){
while(button_pressed()){
rprintf("Pressed\n");
}
return 200000; //1,000,000 = 1 second
}
This seems to bash out 20x the amount of "Pressed" strings sent to the uart.
'xplain! ;D
-
Not quite sure what the question is if there is one, but the if statement will fire once a loop. The while statement runs repeatedly when the button is pressed, extending the initial length before the return delay is factored in.
-
Hi,
'xplain! ;D
I see you have a problem with spelling as well ;)
It's for a reason they're called High Level Languages, as the commands are pretty near plain English and have roughly the same meaning (although some of them needs "closing tags").
IF [you have no money] THEN
Get a job
ENDIF
(Singular event)
WHILE [you have no money]
You cannot buy stuff
WEND
(Ongoing situation until resolved, perhaps by fulfilling first bit of code)
The repeat rate of the WHILE/WEND will depend on what needs done - print commands are slow.
-
In your first example the IF statement is processed once and then you return 20,000 ie a 20ms delay. So your if statement wont be called until 20ms later.
In the second example you are constantly looping around (with no delay) whilst the button is pressed.