Show Posts
Pages: 1 2 [3] 4 5 ... 150
31  Using Arduino / Programming Questions / Re: How to combine Strings and other Variable Types on: September 08, 2014, 02:00:45 am
Are you using an old version of the IDE? Some of the operators may not exist in the old version of the API.

If you have two variables, a String and float, all that is needed is what you first expected:

Code:
String a = "THE ANSWER IS ";
float f = 1.23f;

String b = a + f;

Or just simply:
Code:
a += f;

The String library uses dynamic memory, and people get caught on large concatenations as temporaries will be created ( which also use dynamic memory ). Its easier ( for memory management ) to use c-strings, like econjacks example, however careful use of the String class can make it easy to do many things with text.

32  Development / Other Software Development / Re: Some new core functions on: September 07, 2014, 07:20:04 am
Could you explain to me why the normal map function in the following sketch uses more memory then my templated map function as type long?

Your template is compiled inline.

33  Using Arduino / Programming Questions / Re: Structuring data for viewing/modifying in a hex editor.(Mega2560 R3) on: September 05, 2014, 05:24:47 am
Your hardware can be whatever you like, its the Arduino core API ( software/code ) which is covered by LGPL. The bootloader source my be licensed the same, however you will have to look at the source/documentation.
34  Using Arduino / Programming Questions / Re: working with Array (basic code but very strange) on: September 04, 2014, 03:34:35 am
Quote
I'm not sure it has a name - it's just compile-time allocation.

Anything created on the heap ( globals ) has a storage lifetime called: Static storage duration.

Local static variables also have static storage duration.

Local non-static variables have: Automatic storage duration.

Memory allocated with new/custom allocator are grouped under: dynamic storage duration.

And C++11 introduces thread storage duration.
35  Using Arduino / Programming Questions / Re: Structuring data for viewing/modifying in a hex editor.(Mega2560 R3) on: September 04, 2014, 01:42:51 am
The reason I don't want to have to upload the whole .ino is this will be a consumer product and don't want them to have easy access to the main program.
Bill

If you use parts of the Arduino, unfortunately, to avoid legal action from Arduino or even consumers of your product, you must provide a way to rebuild the software should they choose to modify the LGPL content, like a bug fix or update to the Arduino core.
As the system is statically linked, you will need to provide the source to recompile the application.

If you want your code to be closed source, you can only use code you write, or source code you are licensed to use which does not state the requirement for end users to be able to modify it.
36  Using Arduino / Programming Questions / Re: [unsolved]beginner doubt about variables on: September 03, 2014, 07:22:53 am
Quote
You are trying to create a double bacon genius burger with an empty fridge...
I am going to steal that line. I love it.

No worries, I stole most of it from Homer Simpson.
37  Using Arduino / Programming Questions / Re: Get correctly the sizeof() on: September 03, 2014, 06:04:37 am
Code:
  Serial.println( sizeof( *test[2] ) );
Why does this output 1? And, how, when gamma contains 5 elements, is that useful information?

Because test[ 2 ] is the pointer to gamma, when dereferenced it references a single element of gamma.
Not really useful, unless the type of the array can change between compilations.
38  Using Arduino / Programming Questions / Re: beginner doubt about variables on: September 03, 2014, 05:48:26 am
It doesn't work like that. I am trying to use 1 input, which is vv, to change the value of 3 ouputs, va-c;  here the math is directly go into vs[1-3]; thanks for the help; I will try to figure it out myself later.

What on earth are you trying to do???

Answer questions with a little lot more explanation.

Write a good explanation for this: "I am trying to use 1 input, which is vv, to change the value of 3 ouputs, va-c" i.e give a few steps showing what you expect these values to be over say 5 iterations of your code.

Do you understand the meaning of the assignment operator ( a = b )?
You seem to be failing here, Robin2 pointed out this:
Quote
mval=day;
day=mval;

Do you understand that 'day' is already equal to 'mval' as you just made 'mval' equal to 'day'.

You are trying to create a double bacon genius burger with an empty fridge...

Quote
Or do you want to increment va, vb & vc all at the same time
???... or one depending what the case is?...

You do use a switch don't you? And do they drop through, or did you forget break;?

Quote
It doesn't work like that.

Well that is how it looks like you explained it.
Quote
case 1: // want to add 1 to va (1) for every sec;
(for every sec) va++; // I know I can do this, but I want to try using the value from vv instead;

case 2: // want to add 1 to vb (2) for every sec;
(for every sec) vb++;

case 3: // want to add 1 to vc (3) for every sec;
(for every sec) vc++;

Not even you use vv, it has nothing to do with that code. How do you expect to use it to change va -c?
Do you even know what you are trying to do?
39  Using Arduino / Programming Questions / Re: Get correctly the sizeof() on: September 03, 2014, 05:21:25 am
If you use a multidimensional array you can get the size of each dimension:

Code:
byte test[][5] = {
 {B01111110,B10001000,B10001000,B10001000,B01111110},
 {B11111110,B10010010,B10010010,B10010010,B01101100},
 {B11111110,B10000000,B10000000,B10000000,B10000000},
};

void setup() {
  Serial.begin( 9600 );
  Serial.println( sizeof( test ) / sizeof( *test ) );
  Serial.println( sizeof( test[2] ) / sizeof( *test[2] ) );
  Serial.println( sizeof( test[2][2] ) );
}

void loop() {}

The only way using your current method is to use both the data arrays and 'test' for information:
Code:
byte A[]={B01111110,B10001000,B10001000,B10001000,B01111110};
byte B[]={B11111110,B10010010,B10010010,B10010010,B01101100};
byte gamma[]={B11111110,B10000000,B10000000,B10000000,B10000000};

byte *test[]={A,B,gamma};

void setup() {
  Serial.begin( 9600 );
  Serial.println( sizeof( test ) / sizeof( *test ) );
  Serial.println( sizeof( gamma ) / sizeof( *gamma ) );
  Serial.println( sizeof( *test[2] ) );
}

void loop() {}

Both codes output the result:
Quote
3
5
1

As PaulS says, if 0 can be a terminator, you can use strlen() to calculate the length. ( but then you are simply hiding a nested loop ).
40  Using Arduino / Programming Questions / Re: beginner doubt about variables on: September 03, 2014, 01:37:22 am
I agree, very hard to work out what you are really trying to do.

if you want to remove the switch, you can use an array:

Code:
int vv = 0 ;

int vs[ 3 ] = { 1, 2, 3 }; //instead of va, vb, vc

And the value you pass to the switch, you can index the array with:
Code:
vs[ case - 1 ]++; //remove the -1 if case is range 0 to 2, instead of 1 to 3

It still has no reliance on vv, why should it?

Or do you want to increment va, vb & vc all at the same time... if so dump vb and vc and just use the one variable ( va ), or dump all three and add an offset to vv when you use it.

41  Using Arduino / Programming Questions / Re: random from a char array on: September 02, 2014, 11:42:09 pm
You could avoid the array altogether and save a few bytes of RAM.

Code:
char GetHexVal( const char in = random( 0, 15 ) ){
  switch( in ){
    case 0 ... 9: return '0' + in;
    case 10 ... 15: return 'A' + ( in - 10 );
  }
  return 0;
}

void setup() {
  randomSeed( analogRead( A0 ) );
  Serial.begin( 9600 );
}

void loop() {
  Serial.println( GetHexVal() );
  delay( 500 );
}
42  Using Arduino / Programming Questions / Re: Still stuck with CLASS, "Member functions" and that sort of thing. on: September 02, 2014, 05:47:19 pm
Quote
Then it goes on about the naming convention and ends up by saying the compiler really doesn't care about case (etc) of the names.

Names aren't interchangeable, and case does matter, 'rtc' and 'RTC' are distinct identifiers and is like comparing 'abc' with 'DEF'.

With regards to the initialization:
Quote
DS1307 RTC=DS1307();

A class with a default or no constructor should be constructed like:
Quote
DS1307 RTC;

There is no real reason to use like you have it there, unless there is only a copy constructor, which is a silly design. ( if DS1307(); can successfully default initialize a temporary DS1307 object, then your declaration can most certainly do it to. )

It looks like this was written by someone not too familiar with C++ and they tried to initialize RTC like this:
Code:
DS1307 RTC(); //WRONG

But it wouldn't work so they whacked on the copy initialization.

Quote
int rtc[7];
    RTC.get(rtc,true);

Like I mentioned above, these are different variables. Also, notice the comma, its not a period accessing a member of rtc, its a comma separating two inputs to a function.

Quote
byte alarm_clock::run()

When the function definitions aren't inline with the class definition, the compiler needs to know that run() belongs to alarm_clock, otherwise it would treat it like a global function.
43  Using Arduino / Programming Questions / Re: beginner doubt about variables on: September 02, 2014, 05:33:21 pm
UKHeliBob, I am going to add a caveat to your suggestion as new coders shouldn't use that unless they understand it.  That code will work for numeric values, and only if added the value stay with in the limit of the data type.  If the data type is,  let's say int, then if a + b is greater than what an int can hold that won't work.  This is a fairly common problem to summing values, having the result datatype be too small for the sum.

Really?... Maybe you should try it.
44  Using Arduino / Programming Questions / Re: const int and memory space on: September 02, 2014, 01:37:54 am
To get back to 2278 bytes I had to change the println line to read:
Code:
 Serial.println ((size_t) 5);

  • Serial.println ( 5);
    The literal is signed in this example, and unsigned when cast to a size_t. This calls a different overload of print::println(), and the signed version has a little extra code to handle negative numbers.

    Quote
    Now most people wouldn't think to do that. The conclusion is that salting literal values through your code not only makes it harder to read and debug, but may even use more space rather than less.

    You can avoid this by using an integer literal suffix, the line below should produce code equivalent to using the size_t cast:
    Code:
    Serial.println ( 5ul );
45  Using Arduino / Programming Questions / Re: HTML/CSS/Java Webpage w Arduino Mega & Wifi Shield on: August 27, 2014, 07:35:53 am
As surfertim said, he had problems with the Wifi, which I saw myself when accessing his Arduino.

Try buffer the output like PaulS mentioned so no tiny packets are sent.

Here is a simple class I wrote to do just this: http://forum.arduino.cc/index.php?topic=197103.msg1475339#msg1475339

Used with a large buffer you may see a great improvement in reliability, as multiple lines can end up being sent in one packet.
As it buffers the data until full you need to call buffer.flush(); when you have finished sending the text.
Pages: 1 2 [3] 4 5 ... 150