Saturday 23 July 2016

For Loops 2 - arduino

For Loops 2
 
Excerise: print numbers 1 to 10 & repeat.
 

 
 // variables

int j; // counter
int delayTime=100;

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

void loop()
{
  for (j=1;j<=10;j=j+1){
    Serial.println(j);
    delay(delayTime);
  }
  Serial.println(); // inserts a blank space ..first command after the loop.
}
------------------------------------------------------------- 

example 2
count backwards from 10 , stopping at 1
then looping back to 10

// variables

int j; // counter
int delayTime=100;

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

void loop()
{
  for (j=10;j>=1;j=j-1){
    Serial.println(j);
    delay(delayTime);
  }
  Serial.println(); // inserts a blank space
}

---------------------------------------------------------------------------
 ---------------------------------
-------------------------------------

 
 Links
Tutorial 16

No comments:

Post a Comment