Monday, March 21, 2016

Question 18 (Alternating LEDs)

bool other;
void setup()
{
  pinMode(12, OUTPUT);
  pinMode(13, OUTPUT);
}

void loop()
{
  for (int i = 0; i < 10; i++) // this loop blinks one LED very fast
  {
    digitalWrite(12, HIGH);
    delay(50);
    digitalWrite(12, LOW);
    delay(50);
  }

  if (other == true)  // this LED only goes through a cycle once every 20 cycles of the other LED
  {
    other = false;
    digitalWrite(13, HIGH);
  }
  else
  {
    other = true;
    digitalWrite(13, LOW);
  }
}

No comments:

Post a Comment