Show Posts
Pages: 1 2 [3] 4 5 ... 147
31  Using Arduino / Programming Questions / Re: error: return type specification for constructor invalid on: August 07, 2014, 03:31:29 am
Quote
void S88(int load, int clock, int data, int reset);

Just like the error says, you have a return type on the constructor, which is invalid.

EDIT:

Next errors:
Code:
#include "s88.h"

Needs return types on the definitions.
Code:
<?php  //don't mind this

 
void _loadS88();
 
void _S88Reset();
 
void _S88Clock();
void _S88Low();

//... Needs return types on the definitions.

S88::_loadS88(){}
S88::_S88Reset(){}
S88::S88Clock(){}
S88::_S88Low(){}
32  Using Arduino / Programming Questions / Re: State Machine (Question) on: August 07, 2014, 03:27:01 am
There are a few state machine libraries on the playground, search "arduino state machine library", the first two hits on google are libraries.

They will most probably contain examples of how to use them.
33  Using Arduino / Programming Questions / Re: State Machine (Question) on: August 07, 2014, 02:46:25 am
Depending on what your needs are, a simple switch statement or 'if' will allow you to do that. Do you need to keep 'state' for asynchronous function? Or is everything running synchronously, i.e one after another?

Code:
switch( whichButton ){
  case 0: fooA(); break;
  case 1: fooB(); break;
  case 2: fooC(); break;
}
34  Using Arduino / Programming Questions / Re: What do you think? on: August 07, 2014, 02:37:57 am
Download the IDE 1.5.7, then you can activate C++11, which will be active in 1.5.8 and above.

C++11 is mostly additions to C++98, there are only a handful of rules/keywords/features that have changed significantly ( auto for instance ). So just search for any C++ info, if you need C++11 its there for you to use.

Question 2, haven't read much of your topic, however a robot always needs lasers.

35  Using Arduino / Programming Questions / Re: error: return type specification for constructor invalid on: August 07, 2014, 02:25:58 am
As Hackscribble said, the code you posted worked.

Post the code you used to get the error.

I have attached your project in one file, see if it compiles for you.
36  Using Arduino / Programming Questions / Re: Dynamic array in arduino on: August 07, 2014, 12:51:06 am
Why not pass pointers and a length?
Code:
QueueArray< Node > setPattern( int *amplitude, unsigned long *duration, unsigned count ){
  QueueArray< Node > queue;
  unsigned long nodeDurationSum = 0;
  
  for ( int i=0;i< count ; ++i ){
    Node node;
    nodeDurationSum = nodeDurationSum + duration[i];
    node.setPatternNode(amplitude[i],nodeDurationSum);
    queue.enqueue(node);
  }
  return queue;
}
However, queue will die every call, do you intend it to be static? As returning it by value could double the allocations it makes ( might use dynamic mem also ). Returning a static local as a reference may help, however you'll need more help as the Arduino core is missing some bits which allow this to work.

A template will allow it, however you may end up with multiple copies of the function code being compiled for different array sizes. Arrays are not passed by value, so the only memory you need to watch is the queue.

If using the template and the queue is meant to be static, you'll need it to be global for each template version to see the same queue, otherwise they each have their own.

Code:
template< unsinged N >
  QueueArray< Node > setPattern( int amplitude[ N ],unsigned long duration[ N ] ){
    QueueArray< Node > queue;
    unsigned long nodeDurationSum = 0;
    
    for ( int i=0;i< N ; ++i ){
      Node node;
      nodeDurationSum = nodeDurationSum + duration[i];
      node.setPatternNode(amplitude[i],nodeDurationSum);
      queue.enqueue(node);
    }
    return queue;
}
37  Using Arduino / Microcontrollers / Re: Security of Software on: August 06, 2014, 01:48:43 am
You can use the fuse settings to activate lock bits.
http://electronics.stackexchange.com/a/53293

The chip datasheet and google will have loads more results.
38  Using Arduino / Programming Questions / Re: USE OF Functions with libraries on: August 05, 2014, 08:43:42 pm
To declare a function as a member of a class... outside of the class, you must use explicit scoping ( just like the constructor ),
also when you define a function as opposed to declaring it, you do not use a semicolon before the curly brackets '{}'

Quote
Motor::Motor(int northpin, int westpin,int eastpin, int southpin){

}

void Motor::initMotor(){

}

As mentioned, you can create the servo variables as part of the class. If you declare them in the .cpp it would also work, however the raw servo objects will not be visible elsewhere ( which may be what you want, but similar to declared private in the class ). However get practice with a class as you're using one already.

Code:
class Motor{
public:
  Motor(int northpin, int westpin,int eastpin, int southpin);
  void initMotor();
  void setNMotorspeed(int spd);
private:
  Servo servos[ 4 ]; //0 north, 1 east, 2 south, 3 west
};

//IN CPP FILE
Motor::Motor(int northpin, int westpin,int eastpin, int southpin){
  servos[ 0 ].attach( northpin );
  //... same for 1,2,3
}

void Motor::setNMotorspeed(int spd){
  servos[ 0 ].writeMicroseconds( spd );
}

If you assign the pins to the servos in the constructor, you may find you do not need the variables "int _northpin, _westpin , _eastpin , _southpin;"
39  Using Arduino / Programming Questions / Re: Permanent Saving to EEPROM on: August 05, 2014, 06:43:04 am
I've written a little script to do a similar function, you may find it useful: http://forum.arduino.cc/index.php?topic=229222.0
40  Using Arduino / Programming Questions / Re: How to copy a buffer into a struct? on: August 05, 2014, 06:07:35 am
You do not want a pointer to the array, but a pointer to the first element:
Code:
radio.read(&myRXbuffer, 32);

//Needs to be
radio.read(myRXbuffer, 32);

But, you'll need the address of the structure.
Code:
memcpy( &myVoltsMessage, myRXbuffer, sizeof( myVoltsMessage ) );

Or you can add  a constructor to the objects which can parse the data themselves.
41  Using Arduino / Programming Questions / Re: Posting errors on: August 04, 2014, 08:39:13 am
Try using an incognito window ( google chrome ), or delete the cache and cookies.
42  Using Arduino / Programming Questions / Re: Store multiple data to EEPROM on: August 04, 2014, 08:32:37 am

eeprom_is_ready() is defined in avr/eeprom.h, you do need to include it.

Instead of using your own loop, the macro eeprom_busy_wait() does this for you.
43  Using Arduino / Programming Questions / Re: Return bidimensional array on: August 04, 2014, 08:05:25 am
Did anyone solve this without using struct?
Like in how can I give a 2D array to a function which then returns a (changed) 2D array as a return value?

I'm sure many people are curious how to do this, so if you are willing to go through some details, I can show you how.

First off, lets cover a few points.
Quote
A function can not return an array. A function can return a single value. That single value need not be a simple type. It can be a pointer, a class instance, or a struct. But, it can not be an array.

This is a way to sum it up, however its not quite right.

A function by definition can return any complete type. An array is a type, so why can't we return one?...
Code:
typedef int arr_t[ 10 ];
arr_t allLoco();

This results in: "error: 'allLoco' declared as function returning an array"

What is happening here is the array type arr_t is being returned "by value", similar to int allLoco();. And the standard forbids array assignments. This is no different to passing arrays to functions, they cannot be passed by value.

So how is it fixed: Use a reference or pointer.

To declare allLoco() as a  "function returning a reference to a two dimensional array of Strings" the syntax becomes a little strange.

However this is how to return a static array from a function, without using a struct.
Code:
String (&allLoco())[ numLoco ][ 3 ]{
  static String localVar[ numLoco ][ 3 ] = { { "StrA", "StrB", "StrC" }, {}, {} };
  return localVar;
}

If you want pass the array to the function then return it, the declaration looks like this:
Code:
String (&allLoco(String (&param)[numLoco][3]))[numLoco][3]{
  return param;
}

You can use the returned reference:
Code:
  allLoco()[ 0 ][ 1 ] = 1;

  //...
  String allMyLoco[numLoco][3];
  allLoco( allMyLoco )[ 0 ][ 1 ] = 2;

You can reference the result somewhere else:
Code:
String (&ref)[numLoco][3] = allLoco();

You can also use the result with sizeof to make more flexible code ( this example uses the reference declared above ):
Code:
#define ARRAY_SIZE( x ) ( sizeof( x ) / sizeof( x[ 0 ] ) )

  for( int inner = 0 ; inner < ARRAY_SIZE( ref ) ; ++inner ){ 
    for( int outer = 0 ; outer < ARRAY_SIZE( ref[ inner ] ) ; ++outer ){
      Serial.println( ref[ inner ][ outer ] );
    }
  }

And as it is a real array, not a decayed pointer, you can use it in C++11 for each statements:
Code:
  for( auto &inner : allLoco() ){
    for( auto &outer : inner ){
      Serial.println( outer );
    }
  }

Hope you learn something. BTW there is more to this solution for the Arduino environment. If someone encounters the error referring to 'atexit' I can show you how to fix it.
44  Using Arduino / Programming Questions / Re: Problem with static const byte FontLookup [][5] and PROGMEM - please help! on: August 04, 2014, 07:11:07 am
Did you change the way you read the data when you added PROGMEM?
The data cannot be read directly and needs  a helper function such as pgm_read_byte, or memcpy_P.

http://www.nongnu.org/avr-libc/user-manual/group__avr__pgmspace.html
http://arduino.cc/en/Reference/PROGMEM
http://playground.arduino.cc/Learning/Memory

Search "Arduino PROGMEM" in the forums and google, there are many articles/posts explaining how to do this.

Post your code and we can give a direct example.
45  Using Arduino / Programming Questions / Re: Low memory available on: August 04, 2014, 05:53:20 am
No.
There is no difference in memory usage between using a #define and actually writing the constant in where you need it.

You have no argument from me there, I said: "It'd be the declaration after them that uses the extra memory." Which is referring to the declaration of the variable 'display', not the defines.

Pages: 1 2 [3] 4 5 ... 147