a very basic question

i 'm trying to write a program that triger my food dispensing rig every four hours.but for the love of god ,the programming just keep on giving me error at the the first few line at #define

error: 'voip' does not name a type

this is the program
#define Rled 13
#define Gled 12
#define feeder 11
int mins = 0;
int hours = 0;

voip setup()
{
pinMODE (RLed,OUTPUT);
pinMODE (Gled,OUTPUT);
pinMODE (Feeder,OUTPUT);

}

voip loop() {

digitalwrite(Rled ,HIGH);
for (hours=0;hours <4 ;hours ++){
for (mins=0;mins < 59;mins ++){
delay (60000);
}
}
digitalwrite (Gled,HIGH);
digitalwrite (feeder,HIGH);
delay (5000);
digitalwrite(Gled,LOW);
digitalwrite(Feeder,LOW);
}

i konw this may be a simple error.sorry for the noob question

I'm not sure if this is the EXACT code you have.. but if so;

Your SETUP and LOOP are both using.. voip? Should be void.

As well as your pinMode.. it needs to be exact. C++ is case sensitive.

Instead of pinMODE, use pinMode.

And when you turn your feeder to output.. you use a captial F, which will cause errors.. it needs to be exact.
pinMode(feeder, OUTPUT);

Along with all the digitalWrites... they need to be digitalWrite.. not digitalWRITE, or digitalwrite, or DigitalWrite.. case sensitive!

And again at the bottom, you use a capital F in feeder. Make sure everything is case sensitive :stuck_out_tongue:

hahahah..i know that it would be something stupid like that. ;D ;D ;D.thanks again

Trust me.. I spent almost 2 hours on a sketch just like that my first couple weeks! Haha, it just takes some getting used to!:stuck_out_tongue:

Good luck, glad to see you have a good attitude about it!:smiley:

Better programming practice would be to use

const int Rled = 13;

rather than #define

@Andy Davidson :

Better programming practice would be to use

const int Rled = 13;

rather than #define

Why ?

Even better would be:

const byte rLed = 13;

:wink:

@Andy Davidson :

Better programming practice would be to use

const int Rled = 13;

rather than #define

Why ?

I take the liberty to anser this :slight_smile:

If you specify the datatype, the compiler can do typechecking for you.

For me, the best argument agains using #define directive for defining variables is that there is no scope with a #define.

Say, for instance, that you have a #define called Rled but later in your project, you want to be able to get, say the current on led, and you want to store this as Rled, you cant. Because the preprocessing will replace Rled by a constant and you can not do 13 = 12;

If you include a header with a define, you can not use that name as an identifier. [identifier being name and parameters]

If you, however use a specified variable, you have implicated file scope (unless declared extern). Your compiler will warn you about multiple definitions of a certain identifier (function overloading is somewhat an exception of this).
Additionally you can pass consts by reference if you'd like.
#define Rled 13
Rled has no adress.

In my field of programming (game programming) I often see this use of #define :

#define PLAYER (gameEngine->getPlayArea()->getPlayer())

Why not use Player* player = gameEngine->getPlayArea()->getPlayer(); instead?
That way you are guaranteed to have a valid identifier.

The compiler (often even the IDE) can tell you what type player is.

#define is a bad way to loose control of your variables and dataset.

/me could write more but feel as if I might be a bore

Though if you are trying to squeeze every last byte of RAM, wouldn't #define save RAM?

It is my understanding that variables defined as const are stored in RAM, while a literal like "13" does not occupy RAM.

It is my understanding that variables defined as const are stored in RAM, while a literal like "13" does not occupy RAM.

That is not correct. Variables declared as const are as efficient as values that are #defined.

These two constructs produce the same code, the value of outputPin is not stored in RAM:
const int outputPin = 3;
pinMode(outputPin, OUTPUT);
or
#define outputPin 3
pinMode(outputPin, OUTPUT);

The following (without the const) does store outputPin in two bytes of RAM . It also uses a couple of bytes of flash to for the instructions need to get the value from RAM to pass to the pinMode function
int outputPin = 3;
pinMode(outputPin, OUTPUT);

A few extra bytes usually don't make any difference so my advice is to use the construct that is most comfortable. But if you are concerned about every byte of RAM, the using const is better than #define because the compiler can check that the data types are correct. And its easer for human readers of your code to see what data types you intend.

Another good reason, besides type checking and scope checking, to use consts instead of #defines is semantic checking of the code by the compiler.

Consider this example:

const int x = 14;
int y = 15;

void setup () {
  y = 22;
  x = 22;
}

void loop () {}

The compiler knows that a const should be read-only and that you can't assign a value to it. Compiling this code will give an error:

In function 'void setup()':
 error: assignment of read-only variable 'x'

This helps prevent logic errors in your code well before you ever upload and run it and then are trying to track down a weird behavior.

This example is trivial, of course, but imagine a far more complicated program. The purpose of adopting good programming practices is to protect you from yourself when things get complex!

The compiler also does the semantic check with the value substituted by #define, but the error message is much more cryptic.
If youcome across a message like:
error: lvalue required as left operand of assignment
the compiler is asying that you are trying to change the value of a constant.

Constants are really stored in flash memory? Then is the following "Note on Const" in the avr-gcc documentation not accurate for arduino??

http://www.nongnu.org/avr-libc/user-manual/pgmspace.html