Show Posts
Pages: 1 ... 72 73 [74] 75 76 ... 143
1096  Using Arduino / Programming Questions / Re: String object lib weirdness? on: March 14, 2013, 09:08:40 pm
The string library for arduino is not affected by windows.

The available constructors are:
Code:
explicit String(char c);
explicit String(unsigned char, unsigned char base=10);
explicit String(int, unsigned char base=10);
explicit String(unsigned int, unsigned char base=10);
explicit String(long, unsigned char base=10);
explicit String(unsigned long, unsigned char base=10);

so try specifying the base ( 10 ) or cast the 1234 to a unsigned int or long

Code:
String myNumber( 1234, 10 );
1097  Using Arduino / Programming Questions / Re: Switch-case problem: exit from case during it's running time on: March 14, 2013, 05:54:39 am
If you are using delays in your real code, they halt your Arduino until the time out has been reached. In between each delay you can check for  a 0.

The usual advice is to try understand the 'blink without delay' tutorial.
1098  Using Arduino / Programming Questions / Re: Send message from object to loop() on: March 13, 2013, 10:59:15 pm
The loop inherently loops continually. You could simply check for new data on each iteration, then grab it from the class and print it.
A more complex approach really depends on your needs which you have not stated.
1099  Development / Other Software Development / Re: [MOD] Arduino Enhanced Release 1.0.3 for Windows (installer, drivers, etc) +SRC on: March 13, 2013, 10:20:37 pm
Hi eried,

I was wondering what gcc version ships with the winavr your mod is using. I have some specific c11 code to test and was hoping this would be my easiest path to do so.

From what I can gather, it should be around 4.6.X or above.

The C++0x support in 4.3.2 is not that great at all.
1100  Using Arduino / Programming Questions / Re: Not sure how to handle this incoming string on: March 13, 2013, 08:18:13 am
This seemed to work. With a little tidy up, it should do.

Code:
int InStr( char c, char *str ){

  char *cursor = str;
  while( *cursor ){
    if( *cursor == c ) return cursor - str;
    ++cursor;
  }
return -1;
}

void setup()
  {
    Serial.begin( 9600 );

    char *str = "X:0.00Y:0.00Z:450.20E:0.00";
    float f_X = atof( str + InStr( 'X', str ) + 2 );
    float f_Y = atof( str + InStr( 'Y', str ) + 2 );
    float f_Z = atof( str + InStr( 'Z', str ) + 2 );
    float f_E = atof( str + InStr( 'E', str ) + 2 );
    
    Serial.print( "X: " );
    Serial.println( f_X );
    Serial.print( "Y: " );
    Serial.println( f_Y );
    Serial.print( "Z: " );
    Serial.println( f_Z );
    Serial.print( "E: " );
    Serial.println( f_E );
}

Output:
Quote
X: 0.00
Y: 0.00
Z: 450.20
E: 0.00
1101  Using Arduino / Programming Questions / Re: Not sure how to handle this incoming string on: March 13, 2013, 07:58:36 am
You could find the start index of each letter ( X,Y,Z,E ) and then use atof at the ( start + 1 ) locations to get each float value.

atof: The function first discards as many whitespace characters (as in isspace) as necessary until the first non-whitespace character is found. Then, starting from this character, takes as many characters as possible that are valid following a syntax resembling that of floating point literals (see here), and interprets them as a numerical value. The rest of the string after the last valid character is ignored and has no effect on the behavior of this function.

1102  Using Arduino / Installation & Troubleshooting / Re: code related uploading problem.. on: March 13, 2013, 01:25:36 am
Not that I know of, search the forums though. This particular issue has arisen many times, the answer is probably in one of the threads.

Or you could have a scan through the bootloader code.
1103  Using Arduino / Installation & Troubleshooting / Re: Uploading problem on: March 13, 2013, 01:12:44 am
Don't use !!! it is a code captured by the boot loader or some other intermediate process.

Try printing !! then a separate ! to avoid the problem.
1104  Using Arduino / Programming Questions / Re: A function to get the number of variables in an array? on: March 12, 2013, 11:16:24 pm
Quote
And tell me, why does the struct have a size of 1?

Because you took the sizeof the ArraySize struct. Not something passed to it.

The standard does not allow objects (and classes thereof) of size 0, since that would make it possible for two distinct objects to have the same memory address. That's why even empty classes must have a size of (at least) 1.

Hence:
Code:
struct Empty{};
struct Full{char a;}

Will be the same if the sizeof is taken.

Seeing as you do not create an instance of the object, you do not pay the price, it is a global interface.
1105  Using Arduino / Programming Questions / Re: A function to get the number of variables in an array? on: March 12, 2013, 10:40:33 pm
Creating a static array, while requiring a static for initialisation is just plain ridiculous, how about just typing the number Nick?. The template is not for nonsensical reasons obviously.

I don't think it's ridiculous. Suppose I wanted to define an array of pin numbers, and an array of state data associated with the pins - I'd want the second array to be the same size as the first one without having to hard-code the size of either array.

This is a mildly flawed approach in C++ ( not so much C ), considering structs will remove the data separation and provide encapsulation, and a hard coded value provides safety against silly mistakes. The defines are not specifically for an array, so it will happily compile broken code.

Quote
while I stare at those templates and think WTF is going on here?

Something new to learn maybe?? 
C++ provides these type-safe mechanisms because of the short falling's encountered in C. Using unsafe practices because they are 'easier', in my opinion is not the best way to develop software.


1106  Using Arduino / Programming Questions / Re: A function to get the number of variables in an array? on: March 12, 2013, 08:54:58 pm
And just in case there is a strong aversion to remembering the number, here is a compile time version, which is still safer than the macros provided.

Code:
template< typename T > struct ArraySize;
template< typename T, size_t N > struct ArraySize< T[N] >{ enum{ Size = N }; };

Serial.println( ArraySize< typeof( ledPins ) >::Size );
1107  Using Arduino / Programming Questions / Re: A function to get the number of variables in an array? on: March 12, 2013, 08:10:11 pm
Here is a method that causes the compiler to provide the answer, rather than computing the value.

EDIT: The added bonus is it has protection against non array pointers, unlike the defines above.

Code:
template< typename T, size_t N > size_t ArraySize( T (&)[N] ){ return N; }

Yes, very cunning. Except it doesn't return a constant so it can't be used here:

Code:
template< typename T, size_t N > size_t ArraySize(T (&)[N] ){ return N; }
int foo [] = { 5, 6, 7, 8, 9 };
int bar [ ArraySize (foo) ];   // make another array the same size

Error:

Code:
sketch_mar12c:3: error: array bound is not an integer constant

The NUMITEMS method works there.


Creating a static array, while requiring a static for initialisation is just plain ridiculous, how about just typing the number Nick?. The template is not for nonsensical reasons obviously.
1108  Using Arduino / Programming Questions / Re: A function to get the number of variables in an array? on: March 12, 2013, 09:29:29 am
Unless you use 'malloc' or 'new' to create dynamic memory, this information is readily available by the compiler state. It knows the size of arrays even when there is no clear cut way to grab the info.

Here is a method that causes the compiler to provide the answer, rather than computing the value.

EDIT: The added bonus is it has protection against non array pointers, unlike the defines above.

Code:
template< typename T, size_t N > size_t ArraySize( T (&)[N] ){ return N; }

int ledPins[] = {
  2, 7, 4, 6, 5, 3 };


void setup()
  {
    Serial.begin( 9600 );
    Serial.print( "Array Size: " );
    Serial.println( ArraySize( ledPins ) );
  }
1109  Using Arduino / Programming Questions / Re: Why does the compiler spit out things like this? on: March 08, 2013, 10:30:32 pm
It seems like a common thing. I have had lists of errors pop up occasionally from version 0022 to 1.0.2, especially when cutting or pasting text. Haven't had random scrolling though.

Might be something to do with the IDE virtualizing the files to be compiled.

This is on windows XP / 7.
1110  Using Arduino / Programming Questions / Re: String... need your help.. on: March 07, 2013, 11:56:07 pm
Maybe you are running out of memory or something else is causing a problem.
If I add 'Serial.println( stringTwo );' to the end of the code in reply #5, it prints out:
Quote
byte: 10
92845401834
Pages: 1 ... 72 73 [74] 75 76 ... 143