Pages: [1]   Go Down
Author Topic: square and itoa dont work on ARDUINO DUE  (Read 1403 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,
I dont know why on ARDUINO DUE the square (math library) fubction and the itoa(stdio library) function do not work.
Any solution?
(I Know...use pow or rewrite the function..but why they dont work ????? smiley-slim)
Thank you very much!!!

Luca
« Last Edit: December 21, 2012, 01:37:39 pm by veneridesign » Logged

St. Petersburg, FL
Offline Offline
Jr. Member
**
Karma: 1
Posts: 61
Retired physicist
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

There is a library problem when using IDE V1.5.1r2 and the Due. I had the same problem with the itoa() function on the Due while the IDE would work ok with the Mega. The quickest solution is to switch to the sprintf() function. This function allows you to combine text with converted integers.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Good, Thak you very much!!!!

Luca
Logged

Brighton, UK
Offline Offline
Newbie
*
Karma: 0
Posts: 47
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

There's no mention of a square function in the Arduino reference at http://arduino.cc/en/Reference/HomePage, but it's easy enough to define a C macro to do it.

An itoa function is available if you #include the file itoa.h.

The sketch below uses itoa and square and works as expected with a Due and Arduino 1.5.1r2.

HTH
Jim


#include "itoa.h"
#include "Print.h"

template<class T> inline Print &operator <<(Print &obj, T arg) { obj.print(arg); return obj; }
#define square(x) pow(x, 2)


int count = 1;
int ledPin =  13;    // LED connected to digital pin 13


// Run once, when the sketch starts.
void setup()
{
   Serial.begin(115200);
   Serial.println("Blink");
   count = 0;

   // initialize the digital pin as an output:
   pinMode(ledPin, OUTPUT);     
}

void loop()                     
{
   String s;
        char temp[20];

   Serial << "Blink: Loop " << count << ", " << itoa(count, temp, 10) << ", " << square(count) << (char)10;

   digitalWrite(ledPin, HIGH);
   delay(100);
   digitalWrite(ledPin, LOW);
   delay(900);

   count++;
}
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you , I''l try this solution!

There is no referce about square in the Arduino reference at http://arduino.cc/en/Reference/HomePage because of is defined in math.h http://www.arduino.cc/en/Reference/MathHeader, but is for AVR...


Luca
« Last Edit: December 22, 2012, 08:43:23 am by veneridesign » Logged

Pages: [1]   Go Up
Jump to: