0% found this document useful (0 votes)
29 views

Arduino - Loops

Loops allow code to be executed repeatedly. There are several types of loops in Arduino including while, do while, and for loops. Functions are blocks of code that perform tasks and can be reused by calling the function. Functions allow code to be organized and modular. Calling a function runs the code defined within that function.

Uploaded by

Azam Khan
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views

Arduino - Loops

Loops allow code to be executed repeatedly. There are several types of loops in Arduino including while, do while, and for loops. Functions are blocks of code that perform tasks and can be reused by calling the function. Functions allow code to be organized and modular. Calling a function runs the code defined within that function.

Uploaded by

Azam Khan
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 13

Arduino - Loops

Arduino - Loops

A loop statement allows us to execute a statement or group of


statements multiple times and following is the general form of a
loop statement in most of the programming languages −

2
While loop

3
Do while loop

4
For loop

5
Nested Loop
Loop inside another loop.

6
Functions
Functions
Functions allow structuring the programs in segments of code to perform individual tasks. The typical
case for creating a function is when one needs to perform the same action multiple times in a
program.

8
Functions

9
Functions

void setup(){
  Serial.begin(9600);
}

void loop() {

  k = myMultiplyFunction(i, j); // k now contains 6


  Serial.println(k);
  delay(500);
}

int myMultiplyFunction(int x, int y){
  int result;
  result = x * y;
  return result;
}

10
Functions

11
Functions
Arduino Function Example 3 - BlinkLed3
Blinks an LED - part of a series to experiment with functions
Creative Technology Course by Philip van Allen - ArtCenter College of Design
*/
const int LED1 = 13;
const int LED2 = 5;
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pins as outputs.
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
}

// the loop function runs over and over again forever


void loop() {
blinkLed(100,LED1);
blinkLed(100,LED1);
blinkLed(100,LED1);
blinkLed(300,LED2);
blinkLed(300,LED2);
}

void blinkLed(int delayTime, int led) {


digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(delayTime); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(delayTime); // wait for a second
}

12
4

You might also like