ASURO - 61 -
C for ASURO
9.1.5. Loops
Loops are to be used to repeat command execution.
In a “while”-loop a condition is checked every time the loop is passed. If the condition is true the
command block will be executed. The condition is checked again until it turns to false. At a false
condition the program is continued at the fi rst command following the condition block.
while( Condition)
Command block
Example:
#include “asuro.h”
int main(void) {
MotorDir(FWD,FWD); // Both engines running forward
MotorSpeed(120,120); // Both engines running at around half speed
StatusLED(GREEN); // Turn on Status-LED green
while (PollSwitch()==0) { // As long as there is no collision
SerWrite(“All OK!\n”,10); // ... Feeling groovy ....
}
MotorSpeed(0,0); // Collision! Stop immediatedly!
StatusLED(RED); // Turn on Status-LED red
while (1) {
SerWrite(“Ouch!\n”,5); // start crying!
}
}
A “for (expr1, epr2, expr3)”- sequence is equivalent to:
expr1;
while( expr2) {
Command block
expr3;
}
A “for”-sequence is often used as counter sequence.
for (i = 0; i < n; i++)
. . .
Example:
#include “asuro.h”
int main(void) {
int counter; // defi ne a variable for counting
for (counter =0;counter <10;c+) { // repeat ten times:
SerWrite(“Go ahead!\n”,10); // “Go ahead” message
}
MotorDir(FWD,FWD); // Both engines forward
MotorSpeed(120,120); // Both engines running at around half speed
while (1) { // No more action!
}
}
Содержание DLR ASURO
Страница 36: ...ASURO 36 Software Now this screen will show up Click I Agree This screen appears Click Next...
Страница 37: ...ASURO 37 Software The next screen appears Click Install and the next screen appears Wait...
Страница 40: ...ASURO 40 Software Select on the rigth side C C C C is selected Click Add to insert a new tool...
Страница 45: ...ASURO 45 Software Just for try we will open the file C ASURO_src FirstTry test c Click Open...
Страница 74: ...ASURO 74 B ASURO DIAGRAM Appendices...
Страница 75: ...ASURO 75 Appendices C RS 232 Transceiver...
Страница 76: ...ASURO 76 D USB Transceiver Appendices...
Страница 77: ...ASURO 77 E Block diagram ASURO F Block diagram PIC processor Appendices...
Страница 78: ...ASURO 78 G Contents ASURO KIT Appendices...