Show Posts
Pages: 1 ... 27 28 [29] 30 31 ... 93
421  Using Arduino / Programming Questions / Re: Setting up an Array with Functions and randomly accessing one of them. on: January 30, 2014, 01:32:28 pm
Function pointers are an advanced C topic. They are rarely needed. I used them for a slight speed increase in an expression parser I was writing.

You can also use a switch case like this:
Code:
switch (random_num_0_to_2)
{
    case 0:
    randomblink1();
    break;

    case 1:
    randomblink2();
    break;

   case 2:
    default:
    randomblink3();
    break;
}


Which, IMHO, is much easier to understand.
422  Using Arduino / Programming Questions / Re: Setting up an Array with Functions and randomly accessing one of them. on: January 30, 2014, 12:30:59 pm
Thanks, I find function pointer declarations confusing. I take a stab and then let the compiler tell me how close I am. "Stepwise refinement by error message."
423  Using Arduino / Programming Questions / Re: Setting up an Array with Functions and randomly accessing one of them. on: January 30, 2014, 11:53:27 am
You can certainly create an array of function pointers and call them with a random index.

Code:

void randomblink1() {};
void randomblink2() {};
void randomblink3() {};
void (*funcptrs)()[3] = {randomblink1, randomblink2, randomblink3};

loop
{
funcptrs[get_random_0_to_2()]()
}

424  Using Arduino / General Electronics / Re: why is the inductor used in radio communication ? on: January 30, 2014, 11:20:23 am
Because the inductor complements the capacitor. When excited by an AC signal the reactance of the capacitor is imaginary-negative and the reactance of the inductor is imaginary-positive. Given any inductor and capacitor, at a certain frequency the inductive and capacitive reactances cancel out which will affect only one frequency, leading to a frequency selective circuit.

Why do you think they use capacitors in RF circuits?
425  Using Arduino / General Electronics / Re: Any way to use arduino gsm shield with computer (windows ) on: January 29, 2014, 06:54:47 pm
Why not just get an Arduino UNO to be the interface between the PC and the shield?
426  Using Arduino / Programming Questions / Re: sprintf and binary coded decimal on: January 29, 2014, 10:36:28 am
The best bet is to just use some temporary variables. The compiler is smart enough to optimise them away, but it will force the order of execution.

But your idea will work, too.
427  Using Arduino / Project Guidance / Re: usb floppy on: January 29, 2014, 10:10:52 am
Quote
A floppy drive is a USB master
I don't think this is right. Most have the square plug like a printer, which indicates a slave.

In any case, I have instruments like this and I don't think it will work. I would bet that the internal floppy is not USB, but a standard PC floppy drive. THe USB ports are probably just for printers, and will not recognise a USB floppy even if it was there.

You might try something like this:
http://www.amazon.com/SmartDisk-FlashPath-Floppy-Adapter-SmartMedia/dp/B00005QXW7
428  Using Arduino / Programming Questions / Re: sprintf and binary coded decimal on: January 29, 2014, 09:58:40 am
Quote
Not by the compiler but by the function being called! and for sprintf etc thats specified as the order in which they are written. Think about it and try "writing" your own sprintf()

You are thinking at too high a level. Down in the intermediate code after parsing, things are often implemented as various stacks and operators. It depends on how the stack works as to the order of teh function calls in function parameters.

http://c-faq.com/expr/comma.html

Holmes4, the link has references to the standard.

From K&$II page 63:
Quote
The commas that separate function arguments, variables in declarations, etc., are *not* comma operators and do not guarantee left to right evaluation.
429  Using Arduino / Programming Questions / Re: how to increment and decrement ? on: January 28, 2014, 06:43:00 pm
You will have to put an extra increment at the end of the loop function, or increment by 2:
Code:
time +=2
430  Using Arduino / Programming Questions / Re: sprintf and binary coded decimal on: January 28, 2014, 06:40:01 pm
Welcome to C. While all three function calls are going to be called, the *order* in whcih they are called is not guaranteed. Different compilers might do things differently.
431  Using Arduino / Programming Questions / Re: how to increment and decrement ? on: January 28, 2014, 06:36:50 pm
He knows how to increment, I think he was wondering why it started from 4 all the time!

btw, JHjh,

Code:
time += 1;

is perfectly fine, too.

432  Using Arduino / Programming Questions / Re: how to increment and decrement ? on: January 28, 2014, 06:32:17 pm
something like this:
Code:
int time = 0;

setup()
{
    time = 4;
}

loop()
{
    time++;
}

In your case, time is set to 4 each time loop is entered.
433  Using Arduino / Project Guidance / Re: trying to output raw bytes to serial, getting gibberish on: January 28, 2014, 01:33:20 pm
You probably want to convert your characters to ASCII characters, if you want to see it on a serial terminal. You have to write your own program to handle binary data.

Try Serial.print() instead on each character.
434  Using Arduino / Programming Questions / Re: calculation with ints to get Gps coordinates on: January 28, 2014, 12:12:22 pm
Note that the float and double (which is the same) in Arduino generally has too little precision for GPS calculations.
435  Using Arduino / Project Guidance / Re: problem in interfacing usb host shield and arduino. on: January 28, 2014, 10:21:51 am
Congratulations, things seem to be talking to each other which is 90% of the battle. The USB chip has a set of General Purpose Input/Output pins. The software wants you to connect the inputs to the outputs to test that functionality.

I would think it would let you skip that part, but I don't know the software.
Pages: 1 ... 27 28 [29] 30 31 ... 93