Show Posts
Pages: [1] 2 3 ... 7
1  Using Arduino / Programming Questions / Re: Initializing an array in a class - [SOLVED] on: March 13, 2014, 12:29:40 am
I received an answer from a friend.  Thought I share it here.
The main point is that I was trying to return a pointer to stack variable and use it outside the method.
GetPredefinedArray() copies the predefined memory to a preallocated memory in the main program.
The code below works!  Thanks Isaac!

Code:
class MyClass
{
  public:
    MyClass();
    void GetPredefinedArray(int **outArr);
  private:
    int _predefinedInt;
};

MyClass::MyClass()
{
  _predefinedInt = 7;
};

void MyClass::GetPredefinedArray(int **outArr)
{
  int _arr[][4]={ {1,2,3,4}, {11,12,13,14}, {21,22,23,24} };   
  memcpy(outArr, (int**)_arr, sizeof(_arr)); // copy _arr to outArr.
}

void setup()
{
  int gArr[3][4];
  MyClass myClass;
  myClass.GetPredefinedArray( (int **)gArr );
 
  Serial.begin(9600);
  Serial.print(gArr[2][3]);
}

void loop()
{
}
2  Using Arduino / Programming Questions / Initializing an array in a class - expected primary-expression before '{' token on: March 12, 2014, 09:48:33 pm
I really like how Arduino allows you to initialize multi-dimensional arrays with this syntax:
int x [][3]= {
  {1,2,3},
  {11,22,33}
}

However, this does not seem to work in a Class.  Below is a short sketch illustrating the error that I get:
"expected primary-expression before '{' token "

What I'm trying to do is to encapsulate a bunch of multi-dimensional shape arrays into a Shape class so I can instantiate a Tetris piece of a particular shape and rotation.  Even if there are better way to do this, I'd still be interested in how to pre-initialize an array without having to do this: x[1][2] = 1 repeatedly for every element.

Code:
class MyClass
{
  public:
    MyClass();
  private:
    int _predefinedInt;
    int * _predefinedArray;
};

MyClass::MyClass()
{
  _predefinedInt = 7; // This works fine

  // These work fine but too wordy when I have a big multi-dimension array
//  _predefinedArray[0] = 1;
//  _predefinedArray[1] = 2;
//  _predefinedArray[2] = 3;

  // *** Error: expected primary-expression before '{' token ***
  _predefinedArray = {0,1,2};
};

void setup()
{
  MyClass myClass;
  // blah blah blah
}

void loop()
{
}
3  Community / Exhibition / Gallery / Re: IPCamBot - Digispark, Bluetooth and an IPCam on: March 24, 2013, 09:27:25 am
Well done!  Very small despite the constraints of using LEGO pieces.  I'd like to build one and I tried to go to bricklink.com to find the LEGO parts that I need but quickly got overwhelmed.  Any tips on finding and buying specific LEGO pieces? Thanks in advance.
4  Community / Exhibition / Gallery / 4x4x4 LED Cubes on: March 23, 2013, 02:17:32 pm
I've recently completed two LED cubes.  They're only 4x4x4.  Lame compared to the 8x8x8 or even larger cubes out there, but I had a lot of fun building them and I thought this would inspire others to build their own.  It was a lot of work, but very rewarding.  I don't recommend it as a first Arduino project, but if you've had one or two projects under your belt, you may want to try these.  If you've built one, maybe you can post a link/video on this thread.

4x4x4 Single-color LED Cube

More info at my blog

Charlieplexed 4x4x4 RGB LED Cube

More info at my blog
5  Using Arduino / General Electronics / Re: Need help finding a part on: February 24, 2011, 01:32:34 am
WOW! Reasonable shipping too.
Thanks CrossRoads!
6  Using Arduino / General Electronics / Need help finding a part on: February 24, 2011, 12:08:03 am
I love SparkFun, but I need tons of these for a project and $0.95 a piece seems a bit overpriced.
Can someone help me find this part at Mouser/Digikey so I can compare prices?  Thank you in advance!


http://www.sparkfun.com/products/8432

7  Using Arduino / General Electronics / Re: Options for permanent soldered boards without etching? on: February 19, 2011, 10:51:06 pm
Thanks for all the quick pointers.  Although searching for veroboard at digikey and mouser did not return meaningful results, I've ordered these:  http://futurlec.com/ProtoBoards.shtml

Quite inexpensive and available in many sizes and variations.

For future hunters, I've seen these boards called: protoboard, veroboard, euroboard, stripboard, busboard.
8  Using Arduino / General Electronics / Options for permanent soldered boards without etching? on: February 19, 2011, 11:45:50 am
Etching my own custom board and drilling all the holes seems daunting, so I'm considering this:

http://www.mouser.com/ProductDetail/BusBoard-Prototype-Systems/BR1/?qs=dhMlBWDyGwd3hHrWdzxHJA%3d%3d

Could anyone point me to other (better/cheaper) protoboards? I'm in USA.  Thanks in advance!
9  Forum 2005-2010 (read only) / Troubleshooting / Re: Servo Library, can I address servos dynamically? on: March 14, 2010, 11:23:28 pm
Without seeing the rest of the code, I can't figure out what you're trying to do.

The compiler did not yell at you on the switch and case, so I presume ch is really a char and not a Servo object.

That is why the compiler pukes on ch.write.  Unlike a Servo object, a char is not even an object and therefore it does not know how to write itself.

You probably meant something like this:
Servo myServoArray[4];

myServoArray[ servoIndex ].write(v);

If you post more complete code, we can try to help you further.
10  Forum 2005-2010 (read only) / Bugs & Suggestions / Re: MIDI note player not playing notes on: April 05, 2010, 08:43:01 pm
Wow, good puzzle.
Can you share the circuit and sketch?

My guess is that the circuit is not 100% compatible so you're getting inconsistent signal.  I successfully use my Arduino to play "notes" on my MIDI synthesizer using this circuit.  There are links to MIDI resources that I found useful on that post as well.
11  Forum 2005-2010 (read only) / Bugs & Suggestions / BUG: Serial Monitor keyboard shortcut inserts CR on: March 08, 2010, 10:43:49 pm
I noticed that sometimes the Arduino IDE would randomly destroy my code in the editor.  It could be as harmless as changing number of spaces between functions, or as bad as renaming my variables or missing code chunks.

It turned out that everytime I press the Serial Monitor keyboard shortcut: CTRL+SHIFT+M

Not only the Serial Monitor would open, but Arduino IDE also types a Carriage Return character WHEREVER my selection happens to be!  If I have code selected, it would be removed and replaced with a return.

Not cool... :-(

I'm running Arduino 0018 on 32-bit Windows Vista Ultimate.
12  Forum 2005-2010 (read only) / Bugs & Suggestions / Feature request: Keep Serial Monitor open on: February 04, 2010, 01:43:11 pm
I presume the reason the IDE automatically closes Serial Monitor window is to shield us from seeing all the scary bits going in/out from/to the Arduino.

It would be nice, however, if IDE would automatically re-open the Serial Monitor window when upload is done, or better yet, keep the window open but disable the textbox and buttons during uploads.

Not that big a deal now there's a keyboard shortcut (Ctrl+Shift+M) to re-open Serial Monitor, but it would be nice to have the Serial Window remain open during the debugging cycle.
13  Forum 2005-2010 (read only) / Syntax & Programs / Re: Looking for enum and .h guidance on: March 09, 2010, 09:19:31 pm
Hi,
I tried putting both transmitter and receiver pde in one folder.
IDE yelled at me for having two setup().  :-(

I think I will stick with const and just maintain them in both pde.  I need to accept that in embedded programming I cannot code defensively.

Thanks for your suggestion.
14  Forum 2005-2010 (read only) / Syntax & Programs / Looking for enum and .h guidance on: March 09, 2010, 02:16:14 am
I got enums to work after reading this:
http://www.arduino.cc/playground/Code/Enum

But, I still have questions  :-?

1. So far, I've been creating new .h elsewhere with NotePad and then adding it to my sketch folder via Sketch > Add File... which would more it to the correct place and make it visible as a tab.  Is this really the best way?!

2. I'd like to share enum between two sketches (one is a transmitter, the other a receiver).  How do I do this without duplicating the .h ?  Creating a library seems overkill for a very specific enum.

3. Would I be better off combining both sketches and set a #define to choose whether to compile the transmitter or receiver?
15  Forum 2005-2010 (read only) / Syntax & Programs / Re: Need help with error code on: February 17, 2010, 09:16:43 pm
Just a simple typo:
You need parentheses when defining functions even when they have no parameters, so you need setup() and loop().

There is also a typo on the last two lines of setup(), ledpin12 and ledpin13 are mistyped.  Computers are picky that way. ;-)
Pages: [1] 2 3 ... 7