Blinking LEDs In Sequence (Pin-By-Pin)
Introduction
Arduino is often used with input and output peripherals.
Common output components used with Arduino in mini-projects are LED and Buzzer.
Similarly, a potentiometer is a commonly used input device for analog input to
Arduino. In this article, we will dive into understanding these components and
making exciting mini projects using these.
Using LED As Output
Circuit Diagram:

This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int LED1 = 3; //Declare 1st LED | |
int LED8 = 10; //Declare last LED | |
int lastLed = 0; | |
void setup() { | |
Serial.begin(9600); | |
for(int i= LED1; i <= LED8; i++) //Declare all LED in Output pin mode | |
pinMode(i, OUTPUT); | |
} | |
void loop() { | |
if (Serial.available() > 0) | |
lastLed = Serial.parseInt(); | |
Serial.println(lastLed); | |
for(int i = LED1; i < (LED1 + lastLed); i++)//Turn on Input number of LEDs | |
{ | |
digitalWrite(i, HIGH); | |
delay(2); | |
} | |
delay(1000); | |
for(int i = LED1; i < (LED1 + lastLed); i+=1)//Turn on Input number of LEDs | |
{ | |
digitalWrite(i, LOW); | |
Output Demo:
Comments
Post a Comment