Show Posts
Pages: 1 [2] 3 4 ... 146
16  Using Arduino / Programming Questions / Re: Constructor not called and loop not runnin on: August 14, 2014, 07:38:58 am
Init needs to be called before your serial usage in the constructor,

As the instance is global, your constructor runs before the call to init().

You can move the constructor code to a function named start or begin ( begin isn't the best choice as it is a C++11 free function ).
Then call this function from setup.

17  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:
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...
void (*action(void (*func)(char), char param ))(char) {
    func( param );
    return func;

Using a typedef we can do this:
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.
template< typename Func, typename Param >
  Func action( Func func, Param param ){
    func( param );
    return func;

18  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:
struct abc{
  int a;
  int b;
class def{
    int a;
    int b;

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

void loop(){}
19  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:

Maybe an upgrade took place and http was used for a little while.
20  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 ---

21  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.
22  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.

switch( whichButton ){

  case 0:     //Button 0 pressed

  case 1:      //Button 1 pressed

  case 2:      //Button 2 pressed
23  Using Arduino / Programming Questions / Re: Make an Array "On the Fly" on: August 07, 2014, 04:15:00 am
would probably lead to a loss

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:
 struct Combine2{ operator char*(){ return ( char* ) this; } byte a,b; };SPI.transferBuffer( (Combine2){ x, y }, NULL, 2 );
24  Using Arduino / Programming Questions / Re: PSTR Issue on: August 07, 2014, 03:59:57 am
Which are what on this site?

The button or


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

Code: (title)
//Your code here

and what BulldogLowell said, beat me...
25  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:
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.
26  Using Arduino / Programming Questions / Re: error: return type specification for constructor invalid on: August 07, 2014, 03:31:29 am
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.


Next errors:
#include "s88.h"

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

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

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

27  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.
28  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?

switch( whichButton ){
  case 0: fooA(); break;
  case 1: fooB(); break;
  case 2: fooC(); break;
29  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.

30  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.
Pages: 1 [2] 3 4 ... 146