Can I creat two loops in my code?


hey guys, i'm working on robot project, , want read compass information of robot, here code, it's easy:

#include <arduinorobot.h>

void setup(){

  robot.begin();
  serial.begin(9600);
}

void loop() {

  serial.println(robot.compassread());
  delay(100);

  robot.motorswrite(0,0);
  delay(3000);

  robot.motorswrite(-150,-150);   
  delay(2000);

  robot.motorsstop();         

  delay(2000);

since whole loop takes 7 seconds, robot.compassread() read compass data every 7 seconds? how can read data throughout loop? can creat 2 loops, 1 robot.compassread(), , 1 robot motors?

thank much!

no can't.  need forget ever heard of command called delay() , go learn blink without delay paradigm.  delay blocks code nothing else can run.  instead of doing that, let loop run on , on fast can , keep time see when time make changes.

http://www.gammon.com.au/forum/?id=11411

http://forum.arduino.cc/index.php?topic=223286.0


Arduino Forum > Using Arduino > Programming Questions > Can I creat two loops in my code?


arduino

Comments

Popular posts from this blog

invalid use of void expresion in FlexiTimer2 library

error: a function-definition is not allowed here before '{' token

LED Strip Code