5% OFF Over $19, Code: Elephant5; 10% OFF Over $59, Code: Elephant10



Arduino UNO R3/MEGA 2560 R3 Project 5: LED Chasing Effect

Posted by Fiona Su on

Introduction

We often see billboards composed of colorful LEDs. They are constantly changing to form various effects. In this experiment, we compile a program to simulate chase effect.

Hardware Required

  • Arduino Board x1
  • Led x6
  • 220Ω resistor x6
  • breadboard jumper wire x 13

Video Tutorial

Connection

Connection for REV4:

thumb

Connection for 2560 R3:

thumb

Sample Code

int BASE = 2 ;  // the I/O pin for the first LED
int NUM = 6;   // number of LEDs

void setup()
{
   for (int i = BASE; i < BASE + NUM; i ++) 
   {
     pinMode(i, OUTPUT);   // set I/O pins as output
   }
}

void loop()
{
   for (int i = BASE; i < BASE + NUM; i ++) 
   {
     digitalWrite(i, LOW);    // set I/O pins as “low”, turn off LEDs one by one.
     delay(200);        // delay
   }
   for (int i = BASE; i < BASE + NUM; i ++) 
   {
     digitalWrite(i, HIGH);    // set I/O pins as “high”, turn on LEDs one by one
     delay(200);        // delay
   }  
}

Result

You can see the LEDs blink by sequence.

 

thumb

All Tutorial

Buy 

0 comments

Leave a comment

Please note, comments must be approved before they are published