Arduino Blink

Explanation:

/* */

Block or Multiline Comment: Ignored by the compiler. For our understanding and debugging only.


#define constantName value

Arduino don’t take up any program memory space on the chip. The compiler will replace references to these constants with the defined value at compile time.


//

Single Line Comment: Ignored by the compiler. For our understanding and debugging only.



Function or Method Declaration

returnType functionName(parameter/s) {

//functionBody

}

returnType: 'void' or any one dataType.

functionName: any validName.

functionWork: the purpose of the function.

parameter/s: 0 to n number of parameters.

functionBody: 0 to n function statements

Built-in Functions:

void setup(){

}

returnType: void

functionName: setup

functionWork: the setup function runs once when you press reset or power the board.

parameter/s: Nil

functionBody: Empty

void loop(){

}

returnType: void

functionName: setup

functionWork: the loop function runs over and over again forever.

parameter/s: Nill

functionBody: Empty

{ }

Curly braces: form the body of Functions, Loops, and Conditional Statements.


pinMode(pin, mode);

Configures the specified pin to behave either as an input or an output.

pin: Digital Pins or Analog Pins. The analog input pins can be used as digital pins.

mode: OUTPUT, INPUT or INPUT_PULLUP.

OUTPUT: Pins configured in a low-impedance state. Source or sink upto 40mA of current.

INPUT: equivalent to a series resistor of 100 megohm. With nothing connected to them, or with wires connected to them that are not connected to other circuits, will report seemingly random changes in pin state, picking up electrical noise from the environment, or capacitively coupling the state of a nearby pin.

INPUT_PULLUP: 20K pullup resistors built into the Atmega chip that can be accessed from software.

External PullUP or PullDOWN: Often it is useful to steer an input pin to a known state if no input is present. A 10K resistor is a good value for a pullup or pulldown resistor.

NOTE: Digital pin 13 is harder to use as a digital input than the other digital pins because it has an LED and resistor attached to it that's soldered to the board on most boards. If you enable its internal 20k pull-up resistor, it will hang at around 1.7V instead of the expected 5V because the onboard LED and series resistor pull the voltage level down, meaning it always returns LOW. If you must use pin 13 as a digital input, set its pinMode() to INPUT and use an external pull down resistor.


;

Semicolon: Used to end a statement.


digitalWrite(pin, value);

pin: Digital Pins or Analog Pins. The analog input pins can be used as digital pins.

value: HIGH (5V | 3.3V) or LOW (0V)

Note: If the pin is configured as an INPUT, digitalWrite() will enable (HIGH) or disable (LOW) the internal pullup on the input pin.


delay(ms);

ms: the number of milliseconds to pause. Allowed data types: unsigned long.