Loop

loop()

After calling the setup() function, which initializes and sets the initial values, the loop () function does exactly what its name means, and spins in a loop, allowing your program to perform calculations and respond to them. Use it to actively control the Arduino board.

Example

int buttonPin = 3;
// setup initializes the serial port and button—É
void setup(){
  beginSerial(9600);
  pinMode(buttonPin, INPUT);
}
// the loop checks the state of the button,
// and a message will be sent to the serial port if it is pressed
void loop(){
  if (digitalRead(buttonPin) == HIGH)
    serialWrite('H');
  else
    serialWrite('L');
  
  delay(1000);
}