Digital Output – Blinking LED

Remove everything from the breadboard and let’s make CIRCUIT #1

Copy the code from the manual.

Now make it blink faster!

Blinking 2 LEDs

int L1 =  13;    // LED connected to digital pin 13
int L2 =  12;    // LED connected to digital pin 12

// The setup() method runs once, when the sketch starts

void setup()   {                
  // initialize the digital pin as an output:
  pinMode(L1, OUTPUT);
  pinMode(L2, OUTPUT);
}

// the loop() method runs over and over again,
// as long as the Arduino has power

void loop()                    
{
  digitalWrite(L1, HIGH);   // set the LED on
  delay(1000);                  // wait for a second
  digitalWrite(L2, HIGH);   // set the LED on
  delay(1000);                  // wait for a second
  digitalWrite(L1, LOW);    // set the LED off
  delay(1000);                  // wait for a second
  digitalWrite(L2, LOW);    // set the LED off
  delay(1000); 
}

Make them blink at the same time and alternated.

Blinking 3 LEDs

Now 3 LEDs!

int L1 =  13;    // LED connected to digital pin 13
int L2 =  12;    // LED connected to digital pin 12
int L3 =  11;    // LED connected to digital pin 11

// The setup() method runs once, when the sketch starts

void setup()   {                
  // initialize the digital pin as an output:
  pinMode(L1, OUTPUT);
  pinMode(L2, OUTPUT);
  pinMode(L3, OUTPUT);
}

// the loop() method runs over and over again,
// as long as the Arduino has power

void loop()                    
{
  digitalWrite(L1, HIGH);   // set the LED on
  delay(1000);                  // wait for a second
  digitalWrite(L2, HIGH);   // set the LED on
  delay(1000);                  // wait for a second
  digitalWrite(L3, HIGH);    // set the LED off
  delay(1000);              // wait for a second
  digitalWrite(L1, LOW);    // set the LED off
  digitalWrite(L2, LOW);    // set the LED off
  digitalWrite(L3, LOW);    // set the LED off
  delay(1000);
}

Morse Code

Reproduce the morse code circuit and make it spell PITTSBURGH not “Pitetsbkrrh”:

[youtube http://www.youtube.com/watch?v=3fTYzoSDAS4&w=560&h=315]

Initializing an array or chars:

char message[] = "...___...";
...
//comparing one char at the time
if(message[i] == '.')
{
}
...

Make a program

char message[] = "...___...";
int L1 =  13;  

void setup()   {                
  // initialize the digital pin as an output:
  pinMode(L1, OUTPUT);
}

// the loop() method runs over and over again,
// as long as the Arduino has power 
void loop()                    
{
  int i;

  for (i = 0; i < 9; i = i + 1) {
    //point note the single quote in comparison - 'c' char variable
    if(message[i] == '.')
    {
      digitalWrite(L1, HIGH);
      delay(200);
      digitalWrite(L1, LOW);
    }
    //line
    else if(message[i] == '_')
    {
      digitalWrite(L1, HIGH);
      delay(400);
      digitalWrite(L1, LOW);
    }
    //pause between signals
    delay(200);
  }

  //end message
  delay(500);
}

Assignment 2

Using all of your red LEDs make a circuit that reproduce the Knight Rider (you’re way too young for this reference).

http://www.youtube.com/watch?v=bpqBVk8oYfQ

Upload a video of your working circuit on youtube and post the link on the blog

Posted in

Post a comment