Show Posts
|
|
Pages: 1 ... 3 4 [5] 6 7 ... 15
|
|
61
|
Using Arduino / Programming Questions / Re: Passing char arrays to a function - best practice
|
on: September 11, 2012, 04:40:41 am
|
|
maybe its more handy to know what pointers are. suppose that you do something like this
int A = 10;
Then well thats easy a variable A got assigned a value of 10 But computers dont store the whole alphabet, and your "A" is just easy to read and handy to work with. In reality this "A" is stored somewhere. Imagine if the arduino memory where a street, each house might contain some value like an "A". Now the easiest way to retrieve those values would be if someone told you to go to the address of a house and retrieve what it has stored. This address points you to where it is stored, so POINTERS simply refer to places in memory.
There is a lot of fun that you can do with pointers, because they are not only used for simple variables One could store also an object in an house, and that object could contain more values, like your array.
But there are even more interesting things you might store in a house For example you could put in an object that not only contains an some value, but also the address of the next house to visit and the previous house, and maybe even the house address of the first sidelane. Such more complex objects allow for the creation of database like structures.. In fact databases are made like that.
So from something simple as a pointer, you can get into complex stuff and store any kind of information structure.
Now the speed you get from it is that you only have to refer to something by a pointer and dont have to cast it into another variable for some complex things (like your function). And well it might look a bit scary, its to good to learn about this topic a bit. There are things you can do with it for wich they are handy.
|
|
|
|
|
62
|
Using Arduino / Programming Questions / Re: Analogwrite problem
|
on: September 10, 2012, 05:27:37 pm
|
|
please use code tags when posting ehm did you forgot // marks in your setup part. is see you also use it once / but it should be double // oh and i think analog write can only have values between 0 and 255
|
|
|
|
|
63
|
Using Arduino / Programming Questions / Re: Passing char arrays to a function - best practice
|
on: September 07, 2012, 08:14:29 am
|
please try to adjust your sendmsg function like this, i believe it should work. void SendMsg(char * myMsg) // << points to your array and that should be enough, a basic c++ method { char MsgAndTime[strlen(myMsg) + 10]; strcpy(MsgAndTime, myMsg); strcat(MsgAndTime, " 1:00 PM"); Serial.println(MsgAndTime); }
notice only the main calling method is changed the way you would if calling for an array function variable. if it doesnt work then arduino isnt c++ compliant but i dont doubt it wouldnt work like this.
|
|
|
|
|
68
|
Using Arduino / Programming Questions / Re: For loops??
|
on: September 03, 2012, 06:22:05 pm
|
ok just wrote something simple.. you can ad more if lines if you have more leds, code is real short i guess it should work, not tested it. setup{ state1=false; state2=false; int pin1=1; int pin2=2; int x =0; PinMode(pin1,OUTPUT); PinMode(pin2,OUTPUT); }
// a short method using modulo function >> % <<
void loop(){ x++ if(x%3==0) {state1=!state1;digitalWrite(pin2,state2);} if(x%13==0) {state2=!state2;digitalWrite(pin2,state2);}
delay(.....) }
|
|
|
|
|
69
|
Using Arduino / Programming Questions / Re: Counting pulses
|
on: September 03, 2012, 06:03:43 pm
|
|
somthing like get the current milies time endtime = milies + xxxxx while (milies < endtime) { readpin readsignalstate if (readsignalstate!=lastState){count++;lastState=readsignalState;}
}
|
|
|
|
|
74
|
Using Arduino / Programming Questions / Re: Adding ethernet library from the arduino IDE results in multiple #includes
|
on: September 02, 2012, 06:10:11 pm
|
|
as i explained earlier you might not need them all. (or perhaps you do) programmers of librariers often present you everything, that doesnt mean that your code needs everything but if they didnt provide it, you had to guess the names.. seams a bit harder to me and now you can delete lines that you dont need (or mark them out).
simply mark out check if the code still works if ok you dont need it, if it stops you needed it.
I cannot tell you if the code examples you refer to are from the same date as this library programmers can change whats in their code and how it works, and how it is divided accros their binaries.
|
|
|
|
|