Sunday 22 November 2015

Arduino Lab 2: Multi LEDs

Purpose:
This lab will make multiple LED lights blink.

Equipment:
-4 LEDs
-4 330 ohm resistors
-1 wire (black)
-1 wire (red)
-4 wires (any colour)
-1 Arduino UNO
-1 breadboard
-1 USB cable

Program Details:
-Download Arduino here

Time to Program and Complete:
-Approximately 20 min

Results:
-The LEDs blink repeatedly as the program uploaded: 4 LEDs blink with high power first then with low power, and start over again.

Photo/Video:

   





Program:
int ledPin1=2;
int ledPin2=3;
int ledPin3=4;
int ledPin4=5;

void setup()
{
  pinMode(ledPin1,OUTPUT);
  pinMode(ledPin2,OUTPUT);
  pinMode(ledPin3,OUTPUT);
  pinMode(ledPin4,OUTPUT);
}
void loop() 
{
  int delayTime = 100;
  digitalWrite(ledPin1, HIGH);
  delay (delayTime);
  digitalWrite(ledPin2, HIGH);
  delay (delayTime);
  digitalWrite(ledPin3, HIGH);
  delay (delayTime);
  digitalWrite(ledPin4, HIGH);
  delay (delayTime);

  delay (delayTime);
  digitalWrite(ledPin4, LOW);
  delay (delayTime);
  digitalWrite(ledPin3,LOW);
  delay (delayTime);
  digitalWrite(ledPin2,LOW);
  delay (delayTime);
  digitalWrite(ledPin1,LOW);
  delay (delayTime);
}

Program Modifications:
-There were none

Helpful Tips:
-Name the pins so it is easier to write codes
-Remember not to power on Arduino until you are ready too

References:
-Arduino website: arduino.cc
-New Innovators: Lab 2

No comments:

Post a Comment