Arduino Programming Language: Define

Name

#define

Description

Allows the programmer to give a name to a constant value before the program is compiled. 
In general, the const keyword is preferred for defining constants and should be used instead of #define.

Syntax

#define constName value //there is not a semicolon ;
                        //there is not assignator operator = and the symbol# is necessary.

Parameters

  • costName: the name
  • value: the value of the costName

Usage

Applications

Examples

// replaces MYLED with number 8
// doesn't allocate ram for a variable
#define MYLED 8

void setup() {
pinMode(MYLED, OUTPUT);
}

void loop() {
digitalWrite(MYLED, HIGH);
delay(100);
digitalWrite(MYLED, LOW);
delay(100);
}

Related Functions


Based on the reference originally written by Arduino Community,  wiring.org.co and  arduino.cc