Description: To achieve LED blinking at varying speeds, it is essential to modify the delay time for the LED's ON and OFF states. The fundamental approach involves changing the argument of the delay function based on time. Initially, the variable j is set to 1. A loop is implemented to check if the variable j is less than 20; if j reaches or exceeds 20, it resets to 1. The variable l is defined as the absolute value of (10 - j), which is crucial for designing both decreasing and increasing speeds within a single loop. The variable k is calculated as 1000 - (100 * l), allowing k to decrease until j equals 10 and then increase until j reaches 20. The LED is activated by calling the delay function with k as the argument. The code initializes three LED pins on an Arduino board, sets them as output pins, and controls their blinking pattern based on the calculated delays.
int ledPin1 = 3; // Initialize ledPin1 as digital pin 3 of Arduino board.
int ledPin2 = 4;
int ledPin3 = 5;
void setup() {
pinMode(ledPin1, OUTPUT); // Set ledPin1 (digital pin 3) as output pin
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
}
int j = 1;
void loop() {
if (j >= 20) { // Check if j is 20 or greater
j = 1; // Reset j to 1 to restart the cycle
}
int l = abs(10 - j); // Calculate absolute value of (10 - j)
int k = 1000 - (100 * l); // Determine delay time based on l
digitalWrite(ledPin1, HIGH); // Turn on ledPin1
delay(k); // Delay for k milliseconds
digitalWrite(ledPin1, LOW); // Turn off ledPin1
digitalWrite(ledPin2, HIGH); // Turn on ledPin2
delay(k); // Delay for k milliseconds
digitalWrite(ledPin2, LOW); // Turn off ledPin2
digitalWrite(ledPin3, HIGH); // Turn on ledPin3
delay(k); // Delay for k milliseconds
digitalWrite(ledPin3, LOW); // Turn off ledPin3
delay(k); // Additional delay before next iteration
j = j + 1; // Increment the value of j
}
The circuit described utilizes an Arduino microcontroller to control three LEDs connected to digital pins 3, 4, and 5. The setup function initializes these pins as output, allowing for control over the LED states. The loop function implements a blinking pattern where the delay between turning the LEDs ON and OFF varies based on the value of j, which cycles from 1 to 20. The calculated delay, k, decreases as j approaches 10, resulting in faster blinking rates, and then increases as j approaches 20, creating a visually appealing effect of increasing and decreasing speeds. This approach can be further enhanced by incorporating additional features such as varying the number of LEDs or introducing different patterns of blinking for more complex visual effects.Now, to perform LED blinking in varying speed, we are sure, that we need to somehow change the delay time of an LED to remain in ON and OFF stat. So the main funda is to change the argument to function delay with change in time that`s it. Here, first we initialize the variable j=1. Then, we are going in the loop. And in loop we will check the c ondition for variable j to be less than 20. If, j is greater or equal to 20, then it will be initialize to 1. Now, we will define int l=abs(10-j). which will give the absolute value of (10-j). This is important thing if you want to design decreasing and increasing speed both by one loop. Then, we will write, int k=1000-(100*l). So, variable k will be in decreasing value function with time till j=10. Then, it will start increasing up to j=20. Now, write the statement to glow LED with calling the delay function with passing variable k as an argument. And the code is done int ledPin1=3; //Initialize ledpin1 = digital pin 3 of arduino board. int ledPin2=4; int ledPin3=5; void setup() { pinMode(ledPin1, OUTPUT); // Set ledpin1 (i. e. digital pin 3) as output pin pinMode(ledPin2, OUTPUT); pinMode(ledPin3, OUTPUT); } int j=1; void loop() { if(j=20) // Check if j=20 { j=1; // if j=20, set j=1.
So that the circuit will start again } int l=abs(10-j); // Absolute value of (10-j) = l. int k=1000-(100*l); // Setting the delay function argument digitalWrite(ledPin1, HIGH); // ledpin1 is set to high i. e. ledpin1 is ON. delay(k); // Delay of k milliseconds digitalWrite(ledPin1, LOW); //ledpin1 is set to low i. e. ledpin1 is OFF. digitalWrite(ledPin2, HIGH); delay(k); digitalWrite(ledPin2, LOW); digitalWrite(ledPin3, HIGH); delay(k); digitalWrite(ledPin3, LOW); delay(k); j=j+1; // incrementing the value of j } That`s it buddy.
I hope you will do this little project. And make some innovations like firstdecreasingand thenincreasingfunctions, exactlyopposite to mine.
This circuit employs an 87C57 microcontroller along with several peripherals to convert X-10 power-line carrier-code formats from a personal computer for use with an X-10 power-line interface in a home-control system. Software details can be found in the reference.
The circuit...
The code implementation discussed in the previous post has been initiated. To improve organization, the code has been modularized into functions, simplifying the overall structure. It is available along with the other code. Challenges were encountered in calculating averages while...
Charge a simple servo that only has + and - pins. Typically, the - pin is connected to ground, while the + pin is connected to a digital output from an Arduino. This setup works, but the servo operates weakly...
This is the lowest cost dialing alarm on the market and shows what can be done with an 8-pin microcontroller. The complete circuit is shown below. You cannot see all the features of this project by looking at the circuit...
This circuit features an LED that can be turned off with a puff of air. A condenser microphone (M1) detects the puff. When the push button switch S1 is activated, transistors Q2 and Q3, configured as a latching pair, are...
This circuit demonstrates the use of a standard LED as a light sensor. It utilizes the photovoltaic voltage generated across the LED when exposed to light. LEDs are more cost-effective than photodiodes and feature an integrated filter, which is advantageous...
Two LED CMOS Flasher Circuit Diagram. This is a simple two LED CMOS robot (flasher, multivibrator) circuit using CD4069 six inverters.
The two LED CMOS flasher circuit utilizes the CD4069 integrated circuit, which contains six inverters, to create a multivibrator configuration....
Many published circuits that flash LEDs require 3 volts or more. This circuit utilizes a single inexpensive C-MOS IC and can flash an LED for an entire year on a single 1.5-volt AA alkaline battery cell. The circuit employs a...
Most PC enclosures provide only a single LED to indicate hard disk access, with the LED being connected to the motherboard via a two-pin connector. However, this LED only works with IDE drives, and if a SCSI disk controller is...
We use cookies to enhance your experience, analyze traffic, and (if you allow) serve personalized ads.
By clicking Accept All, you agree to our use of cookies.
Learn more