JensGrabner / tm1638-library

Automatically exported from code.google.com/p/tm1638-library
0 stars 0 forks source link

Cannot display string #3

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.Try to compule the attached  code
#include <TM1638.h>

TM1638 module(3, 2, 4);

String a = 0;
String b = 0;
String StringFinal = 0;

void setup() {  
}

void loop() {
  a = analogRead(1);
  b = analogRead(3);
  stringFinal = a+b;
  module.setDisplayToString(stringFinal), 0xF0);
  delay(100);
}
2.
3.

What is the expected output? What do you see instead?
The code should compile without errors.
The following errors are displayed:
 error: no matching function for call to 'TM1638::setDisplayToString(String&, int)'

What version of the product are you using? On what operating system?

Please provide any additional information below.

Original issue reported on code.google.com by edw...@nardella.ca on 8 Oct 2011 at 4:26

GoogleCodeExporter commented 9 years ago
Apart from an unmatched parenthesis* in your function call, you're trying to 
hand an Arduino library String object to a function that is expecting a C 
null-terminated character array.

To do what you want, you could:
  1) Use sprintf() to make a null-terminated character array (a real C string).
  2) You could not treat what is, after all, a number, as a string, and instead use one of the numerical display functions, such as module.setDisplayToDecNumber().
  3) You could use one of the String object's methods to perform a conversion to a null-terminated character array. Have a look at String.toCharArray().

Option 2 will give you the smallest code, as you dodge having to include the 
String library, and stdio.h, both of which inflate your code by about 2k.

* Should be module.setDisplayToString(stringFinal), 0xF0);

Original comment by mishg...@gmail.com on 9 Oct 2011 at 11:43

GoogleCodeExporter commented 9 years ago
I'm sorry for the late reply, but I'm working on some other personal issues and 
couldn't check this out as regular as I would like. Plus, google code wasn't 
notifying me of new issues.

#1 is right: the problem is that you're using a String library and not standard 
C char arrays.

I can try to look at this as soon as I have some time - maybe add some support 
for the string library.

Original comment by rjbati...@gmail.com on 11 Oct 2011 at 4:27

GoogleCodeExporter commented 9 years ago
Support for String object added and released as version 1.3.0.

Original comment by rjbati...@gmail.com on 20 Oct 2011 at 12:09