Show Posts
Pages: 1 ... 49 50 [51] 52 53 ... 121
751  Using Arduino / Programming Questions / Re: combine vars ? on: March 23, 2013, 03:54:09 am
If your numbers are decimal ( base 10 ),

then simply:
Code:
#define BASE 10
int A = 2;
int B = 3;

int C = A * BASE + B;
752  Using Arduino / Programming Questions / Re: combine vars ? on: March 23, 2013, 12:38:36 am
More info is needed, but here is a guess:

You maybe want two integers stored together, a simple bit shift might do.
Code:

uint8_t A;
uint8_t B;

uint16_t C =( A << 8 ) | B;
753  Using Arduino / Programming Questions / Re: Programming logic question on: March 21, 2013, 01:09:14 am
Maybe this might help: ( x & y ) == z

With a cast to prevent int promotion, this compiles smaller anyway ( untested )
Code:
void loop(){}

uint8_t x;
uint8_t y;

void setup(){
 
  x = analogRead(0);
  y = analogRead(0);
  const uint8_t z = 2;
 
  //if( x == y && x == z ){
   
  if( uint8_t( x & y ) == z ){
    x = analogRead(0);
  }
  y = analogRead(0);
}
754  Using Arduino / Programming Questions / Re: How to delay code execution after boot sequence? on: March 19, 2013, 02:25:05 am
Will delaying at the start of the setup function not do?
Do you want to delay even before main() is called? If so, why?
755  Using Arduino / Programming Questions / Re: Write in the eerpom of ArduinoUno a code RFID (ID20) on: March 16, 2013, 06:04:57 am
Code:
value1 == code

this won't work as you are comparing value1 with a pointer:
Code:
char code[15];

you need to compare with one of the elements. As 'bytesread' is your loop counter, maybe you mean:
Code:
//comparation value in eeprom with value read tag
if( value1 == code[ bytesread ] ){
  Serial.println("ok");
}

Edit: k isn't in scope, replaced with bytesread.
756  Using Arduino / Programming Questions / Re: Issues with StackArray library when passing object to function on: March 16, 2013, 05:36:39 am
On inspection of the stack:

Code:
// push an item to the stack.
template<typename T>
void StackArray<T>::push (const T i) {
  // check if the stack is full.
  if (isFull ())
    // double size of array.
    resize (size * 2);

  // store the item to the array.
  contents[top++] = i;
}

It effectively chews double the memory it needs, that's less than 512 ints on an Uno which could easily support an array of close to 1000 ints.

757  Using Arduino / Programming Questions / Re: Issues with StackArray library when passing object to function on: March 16, 2013, 05:23:50 am
You need to specify a reference in the formal parameter list ( function arguments ),
Code:
void build_simple( StackArray<int> &drumArray );

Also place that line at the top of your sketch to declare the function ( or above its first use ). Here is a fixed sketch:
Code:
#include <StackArray.h>

StackArray <int> BD_rgb_stack;
StackArray <int> SD_rgb_stack;
StackArray <int> ST_rgb_stack;
StackArray <int> FT_rgb_stack;

void build_simple(StackArray<int> &drumArray);

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


void loop(){
  build_simple(BD_rgb_stack);
}


void build_simple(StackArray<int> &drumArray){
  //builds a simple stack
    drumArray.push(1);
    //end stack  
}
758  Using Arduino / Programming Questions / Re: Issues placing "typedef struct" in header... on: March 16, 2013, 04:54:46 am
afremont is on the money, drop the typedef. michinyon shows the main reason why the added confusion is not worth it; by dropping the typedef, your aliased type name suddenly becomes a variable.

aliased structs are only useful in C++ when you actually need something different to what is written before the '{}', such as anonymous structs, i.e
Code:
typedef struct{
  int a;
  int b;
} fred, *fredptr;

//Allows aliased names:
fred a;
fredptr b = &a;


Yes 'struct' is legal on variable definitions, however it is only needed to disambiguate names:

Code:
int fred( int a ){    //Function named 'fred'
return ~a;
}

struct fred    //structure named 'fred'
{ int a;
  int b;
};

struct fred a; //Struct required to disambiguate 'fred'
759  Using Arduino / Programming Questions / Re: String object lib weirdness? on: March 15, 2013, 05:56:43 am
Quote
why doesnt this work?
String myNumber = 1234;
You are assigning a number to a string. I would be surprised if it worked.
Incompatible types.

The String library provides the constructors for that initialisation, then they are turned off by using 'explicit' which requires construction via parenthesis. But still perfectly acceptable to try, seeing as the library provides the concatenation operators for the exact same purpose.

More of an 'incomplete type' rather than incompatible.
760  Using Arduino / Programming Questions / Re: I don't understand the UTouch library. on: March 14, 2013, 11:18:12 pm
There is a config sketch in the examples, have you tried it yet.
761  Using Arduino / Programming Questions / Re: String object lib weirdness? on: March 14, 2013, 11:07:39 pm
The authors simply haven't added in the assignment operator.

Open up the core and add the code below into the string class definition in WString.h

Code:
 String &operator = ( int i_RHS )
    {
      String s_Temp( i_RHS, 10 );
      return *this = s_Temp;
    }

It can only be added into the library, as the operator cannot be global.

Also remove the explicit keyword from the constructors listed below, they prevent code like String aaa = 4567;

you will have to test to see if any other incompatibilities arise.
Code:
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);
762  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 );
763  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.
764  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.
765  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.
Pages: 1 ... 49 50 [51] 52 53 ... 121