Show Posts
Pages: 1 2 3 [4] 5 6 ... 150
46  Using Arduino / Programming Questions / Re: [unsolved]beginner doubt about variables on: September 03, 2014, 07:22:53 am
You are trying to create a double bacon genius burger with an empty fridge...
I am going to steal that line. I love it.

No worries, I stole most of it from Homer Simpson.
47  Using Arduino / Programming Questions / Re: Get correctly the sizeof() on: September 03, 2014, 06:04:37 am
  Serial.println( sizeof( *test[2] ) );
Why does this output 1? And, how, when gamma contains 5 elements, is that useful information?

Because test[ 2 ] is the pointer to gamma, when dereferenced it references a single element of gamma.
Not really useful, unless the type of the array can change between compilations.
48  Using Arduino / Programming Questions / Re: beginner doubt about variables on: September 03, 2014, 05:48:26 am
It doesn't work like that. I am trying to use 1 input, which is vv, to change the value of 3 ouputs, va-c;  here the math is directly go into vs[1-3]; thanks for the help; I will try to figure it out myself later.

What on earth are you trying to do???

Answer questions with a little lot more explanation.

Write a good explanation for this: "I am trying to use 1 input, which is vv, to change the value of 3 ouputs, va-c" i.e give a few steps showing what you expect these values to be over say 5 iterations of your code.

Do you understand the meaning of the assignment operator ( a = b )?
You seem to be failing here, Robin2 pointed out this:

Do you understand that 'day' is already equal to 'mval' as you just made 'mval' equal to 'day'.

You are trying to create a double bacon genius burger with an empty fridge...

Or do you want to increment va, vb & vc all at the same time
???... or one depending what the case is?...

You do use a switch don't you? And do they drop through, or did you forget break;?

It doesn't work like that.

Well that is how it looks like you explained it.
case 1: // want to add 1 to va (1) for every sec;
(for every sec) va++; // I know I can do this, but I want to try using the value from vv instead;

case 2: // want to add 1 to vb (2) for every sec;
(for every sec) vb++;

case 3: // want to add 1 to vc (3) for every sec;
(for every sec) vc++;

Not even you use vv, it has nothing to do with that code. How do you expect to use it to change va -c?
Do you even know what you are trying to do?
49  Using Arduino / Programming Questions / Re: Get correctly the sizeof() on: September 03, 2014, 05:21:25 am
If you use a multidimensional array you can get the size of each dimension:

byte test[][5] = {

void setup() {
  Serial.begin( 9600 );
  Serial.println( sizeof( test ) / sizeof( *test ) );
  Serial.println( sizeof( test[2] ) / sizeof( *test[2] ) );
  Serial.println( sizeof( test[2][2] ) );

void loop() {}

The only way using your current method is to use both the data arrays and 'test' for information:
byte A[]={B01111110,B10001000,B10001000,B10001000,B01111110};
byte B[]={B11111110,B10010010,B10010010,B10010010,B01101100};
byte gamma[]={B11111110,B10000000,B10000000,B10000000,B10000000};

byte *test[]={A,B,gamma};

void setup() {
  Serial.begin( 9600 );
  Serial.println( sizeof( test ) / sizeof( *test ) );
  Serial.println( sizeof( gamma ) / sizeof( *gamma ) );
  Serial.println( sizeof( *test[2] ) );

void loop() {}

Both codes output the result:

As PaulS says, if 0 can be a terminator, you can use strlen() to calculate the length. ( but then you are simply hiding a nested loop ).
50  Using Arduino / Programming Questions / Re: beginner doubt about variables on: September 03, 2014, 01:37:22 am
I agree, very hard to work out what you are really trying to do.

if you want to remove the switch, you can use an array:

int vv = 0 ;

int vs[ 3 ] = { 1, 2, 3 }; //instead of va, vb, vc

And the value you pass to the switch, you can index the array with:
vs[ case - 1 ]++; //remove the -1 if case is range 0 to 2, instead of 1 to 3

It still has no reliance on vv, why should it?

Or do you want to increment va, vb & vc all at the same time... if so dump vb and vc and just use the one variable ( va ), or dump all three and add an offset to vv when you use it.

51  Using Arduino / Programming Questions / Re: random from a char array on: September 02, 2014, 11:42:09 pm
You could avoid the array altogether and save a few bytes of RAM.

char GetHexVal( const char in = random( 0, 15 ) ){
  switch( in ){
    case 0 ... 9: return '0' + in;
    case 10 ... 15: return 'A' + ( in - 10 );
  return 0;

void setup() {
  randomSeed( analogRead( A0 ) );
  Serial.begin( 9600 );

void loop() {
  Serial.println( GetHexVal() );
  delay( 500 );
52  Using Arduino / Programming Questions / Re: Still stuck with CLASS, "Member functions" and that sort of thing. on: September 02, 2014, 05:47:19 pm
Then it goes on about the naming convention and ends up by saying the compiler really doesn't care about case (etc) of the names.

Names aren't interchangeable, and case does matter, 'rtc' and 'RTC' are distinct identifiers and is like comparing 'abc' with 'DEF'.

With regards to the initialization:
DS1307 RTC=DS1307();

A class with a default or no constructor should be constructed like:
DS1307 RTC;

There is no real reason to use like you have it there, unless there is only a copy constructor, which is a silly design. ( if DS1307(); can successfully default initialize a temporary DS1307 object, then your declaration can most certainly do it to. )

It looks like this was written by someone not too familiar with C++ and they tried to initialize RTC like this:
DS1307 RTC(); //WRONG

But it wouldn't work so they whacked on the copy initialization.

int rtc[7];

Like I mentioned above, these are different variables. Also, notice the comma, its not a period accessing a member of rtc, its a comma separating two inputs to a function.

byte alarm_clock::run()

When the function definitions aren't inline with the class definition, the compiler needs to know that run() belongs to alarm_clock, otherwise it would treat it like a global function.
53  Using Arduino / Programming Questions / Re: beginner doubt about variables on: September 02, 2014, 05:33:21 pm
UKHeliBob, I am going to add a caveat to your suggestion as new coders shouldn't use that unless they understand it.  That code will work for numeric values, and only if added the value stay with in the limit of the data type.  If the data type is,  let's say int, then if a + b is greater than what an int can hold that won't work.  This is a fairly common problem to summing values, having the result datatype be too small for the sum.

Really?... Maybe you should try it.
54  Using Arduino / Programming Questions / Re: const int and memory space on: September 02, 2014, 01:37:54 am
To get back to 2278 bytes I had to change the println line to read:
 Serial.println ((size_t) 5);

  • Serial.println ( 5);
    The literal is signed in this example, and unsigned when cast to a size_t. This calls a different overload of print::println(), and the signed version has a little extra code to handle negative numbers.

    Now most people wouldn't think to do that. The conclusion is that salting literal values through your code not only makes it harder to read and debug, but may even use more space rather than less.

    You can avoid this by using an integer literal suffix, the line below should produce code equivalent to using the size_t cast:
    Serial.println ( 5ul );
55  Using Arduino / Programming Questions / Re: HTML/CSS/Java Webpage w Arduino Mega & Wifi Shield on: August 27, 2014, 07:35:53 am
As surfertim said, he had problems with the Wifi, which I saw myself when accessing his Arduino.

Try buffer the output like PaulS mentioned so no tiny packets are sent.

Here is a simple class I wrote to do just this:

Used with a large buffer you may see a great improvement in reliability, as multiple lines can end up being sent in one packet.
As it buffers the data until full you need to call buffer.flush(); when you have finished sending the text.
56  Using Arduino / Programming Questions / Re: error : overloaded 'println... on: August 26, 2014, 03:56:25 am
You most probably have a global String1 declared and you attempt to initialize it with empty brackets:

( re-read your post and it is the problem! )

String String1();

//Change to:

String String1;
57  Development / Other Software Development / Re: New peek function for HardwareSerial on: August 24, 2014, 08:27:26 am
These are awful.

Its a solution, you may not be able to understand it, I'm sorry, however elaborate on your rant, otherwise you just fall in to the category of "one of those C guys".

It seems you still need to fix up the code pauls pointed out to you in the other thread.

58  Using Arduino / Programming Questions / Re: Compiling error on: August 24, 2014, 07:43:39 am
What version of the IDE do you use?

I get a different error:

error: no matching function for call to 'HIDBoot<1u>::HIDBoot(USB (*)())'

USB     Usb();

HIDBoot <HID_PROTOCOL_KEYBOARD>    Keyboard(&Usb);

It compiles after removing the empty brackets. ( its not doing what you think. Compare it to the declaration of void loop(); for example ).
59  Using Arduino / Programming Questions / Re: unable to overwrite a new value in a variable on: August 23, 2014, 07:35:37 am
Calling Serial.flush() will lose input - you really don't want to do this!

Since version 1.0 Serial.flush() only affects output.

To clear/flush the input buffer, something like this is needed:
while( != -1 );
60  Using Arduino / Project Guidance / Re: writing a byte to a processor port on: August 21, 2014, 02:55:36 am
If all pins are on the same port you can write directly to it and modify all 8 pins at the same time.

The AVR source #defines each port in code, on an uno pins 0-7 are all on port D so I can write a byte to it like this:

PORTD = 0xFF; //All bits on

Check out this page:

A mega is better for this ( if you aren't using one already ) as the Uno port D contains the serial RX/TX pins. A mega has a few 8-bit io ports and you can still use the serial to debug.
Pages: 1 2 3 [4] 5 6 ... 150