Show Posts
Pages: 1 ... 3 4 [5] 6 7 ... 147
61  Using Arduino / Programming Questions / Re: Why does sketch using SD.h suddenly need #include <SPI.h> to compile? on: July 30, 2014, 05:00:43 pm
Read the third bullet point:

The SD card uses SPI for its communication.
62  Using Arduino / Programming Questions / Re: How to get Int value ? on: July 30, 2014, 01:38:12 am
Also,  the following line looks invalid.   Even if "mirf.payload"  evaluates to a valid value for the length of an array,   I don't think you can define an array this way.   The array declaration has to either have a length which can be evaluated at compile-time,  or else it has to be dynamically allocated.

byte data[Mirf.payload];

In C++ its an extension provided by GCC, its only part of ISO C99
63  Community / Website and Forum / Re: Unread posts not showing on: July 29, 2014, 11:38:09 pm
1 day I think.

The Arduino boards click over at 3:00pm my local time, Which is in 23 mins, I'll let you know.

Here something cool.

All unread posts from 'Programming Questions' can be accessed from the index:;board=4.0

Which &all can be added to.

But I view more than one forum, so what about filtering out the boards you do not use ( other languages, etc... ). Took a bit to figure out but I got the syntax:

This will show all unread replies from:
  • Programming Questions
  • General Electronics
  • Website and forum;boards=4.0,5.0,24.0;all

notice 'board' is now 'boards', also ';' can replace '&'.

Very handy indeed.
64  Community / Website and Forum / Re: Unread posts not showing on: July 29, 2014, 11:18:09 pm
Its not supposed to show all of them, just the ones in a certain time frame.

If you want to view all the posts, add &all to the end of the URL:

My unread topics is currently 16 pages, with &all its 1086 pages.
65  Using Arduino / Programming Questions / Re: multiple if or for loop with if inside on: July 28, 2014, 09:51:25 pm
That is neat.

I'd be needing to crack a book for a good while to catch up to C++11, for sure. smiley-grin


For quick entry to C++11, searching google for the topics listed in the following link will probably help out:
66  Using Arduino / Programming Questions / Re: #include doesn't seem to register on: July 28, 2014, 09:29:07 pm
When I compiled this:

#include <MakeItRobotics.h>//include library

MakeItRobotics line_following;//declare object

void setup() {}

void loop() {}

I got:
Sketch uses 1,546 bytes (4%) of program storage space. Maximum is 32,256 bytes.
Global variables use 196 bytes (9%) of dynamic memory, leaving 1,852 bytes for local variables. Maximum is 2,048 bytes.

Did you restart the IDE? I have never imported, but manually dumped the folder in the libraries folder ( which requires a restart ).
Open your libraries folder and see if it imported correctly?
67  Using Arduino / Programming Questions / Re: Do I need to reset variables to 0 ? on: July 28, 2014, 11:46:25 am
Variables obtained by assignement are automatically reset when a new assignement is done ? Can you confirm?

loose the notion of reset, a String can be assigned an empty string, and an int can be assigned zero, if this is what you need. If you need it to have real data, then just assign that to it.

if I well understand, only variables obtained by += have to be cleared for new usage ?

The += operator is one example. I used it as the String library overloads it. If you have control of the code, just change the '+=' to '='. Do you understand the differences between the two?

I need to simplify my sketch because I have to care about the size of it because it is a very big sketch and the Uno memory is limited.

Then you should probably stick to character arrays instead of the String library. To a novice C++ programmer the memory usage can seem quite unpredictable when using Strings.
68  Using Arduino / Programming Questions / Re: Do I need to reset variables to 0 ? on: July 28, 2014, 09:42:46 am
No, you just need to set it to something useful before its reused. Which you do.
semicolunPosition = trimIncomingString.indexOf(';');

We can't see where trimIncomingString is populated, so it might if it is populated using '+=' and you do not want the old data. If there is only a simple assignment, then it is replaced.

Why do you ask, some debugging problem?
69  Using Arduino / Programming Questions / Re: Array Difficulties on: July 28, 2014, 09:34:22 am
There are 10 different segments of LEDs that can all be different colors, so I'd think each LED segment world require a color right?

For sure, but if the 10 values for each set are the same, you should only need to store one value for each set which you can just repeat.

AWOL pointed out you could simply shift 0xF00000 right ( 4 * x ) bits where x is the index of the segment. There is no real need for an array.

What is your motivation for a first dimension of 1? It is the same as not having the extra dimension at all.

Also the repeating variable names requires repeated code to use, arrays are extremely useful for this situation ( 1 array with an extra dimension ):
const unsigned long color_1[10];
const unsigned long color_2[10];
const unsigned long color_3[10];

const unsigned long color[ 3 ][ 10 ];

70  Using Arduino / Programming Questions / Re: multiple if or for loop with if inside on: July 28, 2014, 02:28:33 am
Break is a good solution to your stop variable, however as the code is fairly straight forward, we can do it with out any if statements at all:

char counterTest = 0;
for(int i = 16 ; i && array[i-1] ; --i, ++counterTest );

If you enable C++11 in IDE 1.5.7, you could also do this:
for( auto i : array ){
  if( i == LOW ) break;  
71  Using Arduino / Programming Questions / Re: Losing variable value when adding function to code on: July 24, 2014, 02:18:13 am
It wouldn't matter if the function parameter was named 'm' or 'p', if its not a reference or pointer, you have a copy and therefore are not referring to the same object inside the function.

As the String is global, you can just access it without an extra parameter, however if the function was in a different CPP file you will need to 'pass' it.

By reference:

int checkFunctions(String &m){
  m += "Hi";
  return 1;

Or by passing in a pointer type.
int checkFunctions(String *m){
  m->concat( "Hi" );
  return 1;

Then any changes to the function variable, will be in reference to the global variable.

Call the first version exactly the same as you had it, the second simply needs the strings pointer.

String m;
checkFunctions( m ); //Reference
checkFunctions( &m ); //Pointer
72  Community / Website and Forum / Re: How do I Start a Poll? on: July 22, 2014, 01:54:56 am
I remember polls being disabled. Is this a permission only moderators have?

I had a look and I cant see any poll button.
73  Using Arduino / Installation & Troubleshooting / Re: Code is not getting burn in Arduino Uno on: July 22, 2014, 01:52:10 am
Its been a common question, search the forum for the string "Avrdude: skt500_getsync(): not in sync" and you'll probably find a few things.

To start off with, do you have anything plugged into pins 0 and 1, if so disconnect those or use different pins. If you need a second serial interface, you can search for examples using the SoftwareSerial over different pins.
74  Using Arduino / Programming Questions / Re: stopping a sketch once completed on: July 21, 2014, 07:43:04 am
There are a few different methods for stopping a sketch explained here:
75  Using Arduino / Programming Questions / Re: #define, int or const int on: July 20, 2014, 10:52:46 pm
I guess nobody else uses enumerators? How odd. I just luvemup!

I do, was just doing a post:

GoForSmoke is correct, an enum is a great way to define constants, which are still symbols, not copy 'n' paste jobs.
C++11 will allow enums to become one of the better choices, as the enum values are no longer in the global scope, which can allow more creative control.

Whats more is they can have their size controlled, there is no behind the scenes conversions of integer literals. ( notice the : uint8_t )

Currently an enum  can take the form:
enum SystemPins{
  buttonPin = 2,

You could separate the like pins into different enums, however the point is they are all global names.

When the IDE 1.5.8 is released we can do this:

enum{ ledWarningPin = 2 }; //Normal enum

enum class HID : uint8_t { //Strongly typed enum
  button0 = 3,
  button1 = 4

enum class LCD : uint8_t {
  data0 = 5,
  data1 = 6,
  data2 = 7,
  data3 = 8,    
Pages: 1 ... 3 4 [5] 6 7 ... 147