1. Create a new sketch.
Paste this in. This is the original Blink sketch
int ledPin = 13; // LED connected to digital pin 13
void setup()
{
pinMode(ledPin, OUTPUT);
}
void loop()
{
digitalWrite(ledPin,HIGH);
delay(1000);
digitalWrite(ledPin,LOW);
delay(1000);
}
Compile it and run it. The LED blinks, as expected, and in Arduino I see
Binary sketch size: 896 bytes (of a 30720 byte maximum)
2. Create a new sketch.
Past in the following. This is a macroized Blink sketch:
#define ledon digitalWrite(ledPin,HIGH)
#define ledoff digitalWrite(ledPin,LOW)
int ledPin = 13; // LED connected to digital pin 13
void setup() {
pinMode(ledPin, OUTPUT);
}
void loop()
{
ledon;
delay(1000);
ledoff;
delay(1000);
}
Compile it and run it. The LED blinks, as expected, and in Arduino I see
Binary sketch size: 896 bytes (of a 30720 byte maximum)
3. Create a new sketch.
Past in the following. This is a functionalized Blink sketch:
int ledPin = 13; // LED connected to digital pin 13
void setup()
{
pinMode(ledPin, OUTPUT);
}
void loop()
{
ledOn();
delay(1000);
ledOff();
delay(1000);
}
inline void ledOn(void)
{
digitalWrite(ledPin,HIGH);
}
inline void ledOff(void)
{
digitalWrite(ledPin,LOW);
}
Compile it and run it. The LED blinks, as expected, and in Arduino I see
Binary sketch size: 896 bytes (of a 30720 byte maximum)
So they all "work" the same. (Of course if you are using a '168 instead of a '328, the maximum memory allowed will be less, but the three will be the same size.)
Furthermore...
The code created by the compiler is exactly the same in all three cases. (Yes, exactly.) Same size, same performance. Exactly.
Which do you prefer? It's your program and your decision.
In other words: Chacun à son goût.
Regards,
Dave