math library issue?

This forum is for all discussion about version 0.94 of the Simulator for Arduino program

Moderator: Adrian

FolkEngineer
Posts: 8
Joined: Mon Feb 20, 2012 2:00 pm

math library issue?

Postby FolkEngineer » Fri Feb 24, 2012 10:51 am

example code
-------------
int read1 = 5;
int read2 = 10;
int sum = 0;

void setup()
{
}

void loop()
{
sum = abs(read1-read2);
}
---------------

This gives me the error "unknown command or variable: abs(read1-read2);
For the simulator do I need to #include some standard libraries that are automatically included with the Arduino compiler?

By the way, when I click on "show help", I get nothing?

Thank you,
Pete

Simulator_admin
Site Admin
Posts: 239
Joined: Thu Feb 02, 2012 6:07 pm

Re: math library issue?

Postby Simulator_admin » Sat Feb 25, 2012 8:04 pm

Hi Pete, thanks for the post. We may have to put you on salary for picking up all these issues. We have added support for the abs function in v0.94D and one of the new sketches (test6?) has some test code. We will check this next week and let you know if this example code now runs and on which version. At present, the Simulator program is in the process of having new features added, so there will not be any more patches until v0.95 which will be released after thorough testing.

On another note, we will be adding credits to the user manual (real-names only), and will be including everyone who has a found a fault ( there is a big list now). This project has become more of a joint effort so send us an email or message if you want to be included towards the top of the list. Thanks

FolkEngineer
Posts: 8
Joined: Mon Feb 20, 2012 2:00 pm

Re: math library issue?

Postby FolkEngineer » Mon Feb 27, 2012 3:02 pm

Rather than start yet another thread, I thought I'll just ask my latest query here.
I'm having trouble with and'ing two variables and casting.
Following program as I ran it on a real Arduino:
--------
void setup() {
Serial.begin(1200);
}

void loop() {
int con = 756;
byte b1 = (byte)(con & 255);
Serial.print(" b1 = ");
Serial.println(b1);
int i1 = con & 255;
Serial.print(" i1 = ");
Serial.println(i1);
byte b2 = (byte)i1;
Serial.print(" b2 = ");
Serial.println(b2);
delay(10000);
}
--------------
In all three printouts on the real thing, it correctly printed 244 (base 10), which I believe is the right answer. I'm obviously just trying to get the lower byte.
If you step thru the code on the simulator, it gives 756 for i1 and 0 for the b1, b2, all of which aren't correct, right?

Pete

P.S. Thx for the offer of credit, I'm just happy to have a simulator period! It has already saved me a lot of debugging in the lab with serial prints!

Simulator_admin
Site Admin
Posts: 239
Joined: Thu Feb 02, 2012 6:07 pm

Re: math library issue?

Postby Simulator_admin » Mon Feb 27, 2012 4:37 pm

OK, I think we got this one. It was caused by the (byte), so while the program found the 244, it then threw it away. We just finished testing v0.95, so I guess we will now have to retest before releasing.

By the way, when I click on "show help", I get nothing? Also, with the help, the Simulator program needs to be in the same directory as the help file which is the .chm file. The help cannot be accessed if the Simulator is run from inside a zip file but should be OK if extracted into a directory. Pressing F1 should open up context sensitive help and a good way to test this is to click in the program window, variables area and Arduino picture.

Thanks.


Return to “Version 0.94”

Who is online

Users browsing this forum: No registered users and 1 guest