InnoVech
Published

Lesson 6 - While and For Loops

We are now moving on to complex functions and in lesson 6 we will learn to use While and For Loops with Arduino.

IntermediateProtip1 hour20,116
Lesson 6 - While and For Loops

Things used in this project

Story

Read more

Code

While and For Loops

Arduino
Lesson 6 Source Code
//Complete Guide to Arduino
//Created by Zaqyas Mahmood, InnoVech
//Lesson 6 While and For Loops

/////// Constant Variables Intialised ///////
const int LED  = 13;
const int LED2 = 12;

////// Changeable Variables Intialised ///////
int Count = 0;
int Count2 = 0;

void setup() 
{
 pinMode(LED, OUTPUT);
 pinMode(LED2, OUTPUT);
}

void loop() 
{
  digitalWrite(LED, HIGH);  //Turn off LED1 on MFS
  digitalWrite(LED2, HIGH); //Turn off LED2 on MFS

  //The while condition true until Count is less than 10
  while (Count <= 10)
  {
    digitalWrite(LED, HIGH);
    delay(50);
    digitalWrite(LED, LOW);
    delay(50);
    Count++;
  }
  digitalWrite(LED, HIGH); //Once Count is equal to 10 turn LED off


  //The For loop initialises Count2
  //The Condition is true until Count2 is less than or equal to 25
  for (Count2; Count2 <= 25; Count2++)
  {
    digitalWrite(LED2, HIGH);
    delay(50);
    digitalWrite(LED2, LOW);
    delay(50);
  }
  digitalWrite(LED2, HIGH); //When Count2 is equal to 25 turn LED2 off
}

Credits

InnoVech
11 projects • 8 followers
We strive to share our projects with engineering hobbyists and students who are driven to play their roles in the future of engineering.
Contact

Comments

Please log in or sign up to comment.