single step not working after "if"

This forum is for all topics related to Simulator for Arduino v0.97. Please include sample code where possible.

Moderator: Adrian

smac
Posts: 1
Joined: Fri Feb 22, 2013 5:37 am

single step not working after "if"

Postby smac » Fri Feb 22, 2013 5:43 am

UPDATE: Pretty sure this has to do with not having the standard libraries set up. I'm working on that line of attack. Also, apparently the simulator version I'm running is v0.98b

Also - the free version delay (300s) is pretty long. I'm trying to evaluate whether to buy the software, but it takes 5 minutes to do pretty much anything, which makes the evaluation process difficult. You might think about having the delay kick in after a few days, which would allow a reasonable evaluation period.

I just downloaded and installed the simulator. Maybe I'm missing something, but I tried running a simple binary search program (using a servo as the output). The code is shown below. The problem I ran into is, in the loop() function the emulator steps through the if() statement and then skips the servo.write() and everything below it and jumps right back to the top of the loop. It doesn't matter whether I use step into or step over. This code runs fine on the board itself.

Am I doing something wrong?

Thanks

Code: Select all

[i]#include <Servo.h>
Servo myServo;

int findPos = 90;        // Unknown position to be found.

int lastPos = 180;       // Where we were last step.
int currentPos = 0;      // Where we are now
int pos = 0;              // Where we want to go next.

void setup() {
  myServo.attach(9);
  myServo.write(currentPos);
  delay(1000);
}

void loop() {

  if(findPos >= currentPos) {
    pos = currentPos + abs(lastPos-currentPos)/2;
  } else {
    pos = currentPos - abs(lastPos-currentPos)/2;
  }
 
  myServo.write(pos);
  lastPos = currentPos;
  currentPos = pos;
 
  delay(1000);
}
[/i]

User avatar
Adrian
Super user
Posts: 56
Joined: Thu Jan 10, 2013 10:22 pm

Re: single step not working after "if"

Postby Adrian » Mon Mar 04, 2013 5:31 am

Hi SMAC,

Thank you very much for your detailed email.

I have to say that the code appears to work fine for me.
However I should add some caveats
Since I am involved in beta testing, the latest version I have runs fine
the closest version that I have to you also works fine, but exhibits a bug with the else statement (place the else on a different line to the close brace } as a work-around)
We have seen issues with evaluating functions, can you try evaluating previous to your if statement and see if that helps?

Kind regards
Adrian
Apologies for being opinionated - it's nothing personal, feel free to complain.
usual system: Pro V0.98 Arduino Mega 2560 Samsung i5-3210M 2.5Ghz 6GB windows home premium SP1


Return to “Version 0.97”

Who is online

Users browsing this forum: No registered users and 1 guest