Way New to Arduino.. but have written Shell, PERL, PYTHON, PHP, BASIC.. and played a fair bit with PICAXE - just because I've tinkered, doesn't mean I've mastered!
so I am real new to C, been playing seems ok. I have played with the sketch that just flashes D13, the one that allows me to talk to the DS3232 board etc - all good. So now I would like to just have a sketch that flashes D13 twice, reads the time in(non interactive to the console user) an does a serial print. So I am thinking, just take bits and pieces from the code I have been using, which I tried, but then I got compile errors about variables not being defined, labels unknown etc etc. I think what's confusing me is I don't know what is a C core statement, and what is a function from a .H file etc.
SO.. I went and opened up a .H file (DS3232RTC.h) and then RTC.H etc.. they're pretty full on. I guess what I'm thinking is I don't want to write a full set of code from the ground up, but these .H files - are they documented.. ie at a high level can a dummy like me look for a doco on RS3232RTC.h which tells me how to use it, what syntax to use and what to expect back etc..?
Appols for perhaps stupid question!
please tell me there are some people in the Australian time zone on here
The major downside of opensource software is that there usually isn't documentation. Writing a reference manual is not as much fun as writing code.
Perhaps all you need to do is add some variable definitions at the top of your sketch. For example
int missingVariable1;
char missingVariable2;
You may need to do some trial and error to figure out the correct type of the variable. If you look at the code with a decent text editor that can find and highlight all instances of a variable it will narrow the focus of your reading and you might get a clue. Indeed there should be a definition in the original source file.
I think what's confusing me is I don't know what is a C core statement, and what is a function from a .H file etc.
It looks like your previous experience is with languages that let you create variables out of thin air, whenever you need them, just by mentioning them, right?
"A = "testing"" results in a string variable named A being created and assigned the string.
A big difference between those, and C/C++ is that C/C++ wants to to DEFINE the variables you are going to use, before you use them. "DEFINE" means specifying the type, name, and possible initial value. So the general structure of a C program looks like:
// global variable declarations
int blinkled = 13; // initialized integer
unsigned long lastmillis;
typeoffunction functionname (function paramater names and types)
{
// variables declarations local to function
int i;
unsigned long now = millis();
// code for function.
statements_end_with_a_semicolon;
{ // multiple (block) statements inside braces act like a single statement
int temp; // and can even have variables local to the block
}
}
There's no special starting location in C/C++; all your code is in functions, and there is a convention defined "elsewhere" that says "we're going to start off by calling the main() function" or "we'll start by calling setup(), and then call loop() over and over again."
C++ has an added convenience that you can define variables IMMEDIATELY before you use them, as in for (int i=0; i <10; i++) {
But you still have to define the type...