Show Posts
Pages: 1 ... 3 4 [5] 6 7 ... 149
61  Using Arduino / Programming Questions / Re: How to pass function / variable name? on: August 13, 2014, 09:13:15 am
Some people have problems with complex data definitions. For example, what is:
Code:
double (*(*pf)())[3][4];

It looks like, pf is a pointer to a function returning a pointer to a multidimensional array of doubles.

For a little handy info, dealing with function pointers is one place where templates can seem like the easy solution. Even if typedef is used. Consider a function that takes a function pointer with a parameter, calls it and returns it.

Too many brackets for my liking...
Code:
void (*action(void (*func)(char), char param ))(char) {
    func( param );
    return func;
}

Using a typedef we can do this:
Code:
typedef void (*Func)(char);

Func action( Func func, char param ){
  func( param );
  return func;
}

However it is still hard coded to the datatypes and must be changed when ever the function prototypes change, and it doesn't allow expansion to functions that may return a value or take a different parameter type.

A template makes this easy, and it works with C++11 lambdas, the above methods are specifically for functions.
Code:
template< typename Func, typename Param >
  Func action( Func func, Param param ){
    func( param );
    return func;
}


62  Using Arduino / Programming Questions / Re: Little Help Understanding What's Happening In Code Between Library & Sketch? on: August 13, 2014, 05:45:08 am
A struct is not a class - it is just a container for data. A struct can contain several different data items with different data types. If you think of a byte as a container for 8 bits of data a struct is just a more complex container.

In C++ classes, structs, and unions are all types of classes. The only difference between a class and a struct is the members of a struct are all public.

In fact when writing a class that must be a POD, you can write it easier by using the 'struct' class key rather than 'class'. This is because a POD must be trivial and a standard-layout class, which must have no protected or private members.

Uncomment the 'public:' to allow POD initialization:
Code:
struct abc{
  int a;
  int b;
};
class def{
  //public:
    int a;
    int b;
};

void setup(){
  abc a = {1,2};
  def b = {1,2};
}

void loop(){}
63  Community / Website and Forum / Re: HTTPS ? on: August 10, 2014, 11:14:44 pm
The index page has a log in link which uses SSL: https://id.arduino.cc/auth/login/?go=1

Maybe an upgrade took place and http was used for a little while.
64  Using Arduino / Programming Questions / Re: program is not working after few hours until reset on: August 10, 2014, 09:25:36 pm
--- Insert additional 'failure to post your code' sarcasm here ---

65  Using Arduino / Project Guidance / Re: how to listen serial.print with flash ? on: August 07, 2014, 02:00:59 pm
You may need to re-phrase your post. Its not clear what you are asking.

Do you use an ethernet shield? Or serial communication?

flash is typically what is known as the program memory on the Arduino. Are you talking about the PC software?

If so, you can try and code your app to resend if it doesn't receive a response in a certain time. You will also have to make sure the Arduino can send a response with every request it receives.
66  Using Arduino / Programming Questions / Re: State Machine (Question) on: August 07, 2014, 04:33:00 am
What is wrong with the switch statement I provided above, is that what you are referring too?

First you work out the number or id of the button pressed, then the switch runs a function depending on which button was pressed. If I add some more lines, you can see each case has a break.

Code:
switch( whichButton ){

  case 0:     //Button 0 pressed
    fooA();
    break;

  case 1:      //Button 1 pressed
    fooB();
    break;

  case 2:      //Button 2 pressed
    fooC();
    break;
}
67  Using Arduino / Programming Questions / Re: Make an Array "On the Fly" on: August 07, 2014, 04:15:00 am
Quote
would probably lead to a loss

Really,
that is inline, it constructs a temporary object. So, you want to do something, but write no code for it...

Code size != Compiled size.

If you are aiming for less lines just put it all on one:
Code:
 struct Combine2{ operator char*(){ return ( char* ) this; } byte a,b; };SPI.transferBuffer( (Combine2){ x, y }, NULL, 2 );
68  Using Arduino / Programming Questions / Re: PSTR Issue on: August 07, 2014, 03:59:57 am
Which are what on this site?

The button or

Manually:

[code=title]//Your code here[/code]

Produces:
Code: (title)
//Your code here

and what BulldogLowell said, beat me...
69  Using Arduino / Programming Questions / Re: Make an Array "On the Fly" on: August 07, 2014, 03:51:08 am
You can make the array static, then write to each element.

Or mask the bytes together, however testing would have to prove any benefit ( or loss ).

Why not a C++ approach then:
Code:
struct Combine2{
  operator char*(){ return ( char* ) this; }
  byte a,b;
};

//...

SPI.transferBuffer( (Combine2){ x, y }, NULL, 2 );

If you do not like the compound literal, you can provide a constructor.
70  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(){}
71  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.
72  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;
}
73  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.

74  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.
75  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;
}
Pages: 1 ... 3 4 [5] 6 7 ... 149