Question

In: Physics

Write a function that can be used to blink an LED when called.

Write a function that can be used to blink an LED when called.

Solutions

Expert Solution

Since the number of pin, to which LED is connected, is not given in the question, let's assume it to be x. Please change it accordingly. We write,

>>>>>>

int ledPin = x;

>>>>>>

Then we assign the pin as an output by writing,

>>>>>>

void setup()
{
pinMode(ledPin, OUTPUT);
}

>>>>>>

And finally after these assignments, we use loop function to turn LED ON and OFF and digitalWrite funtion to assign ON and OFF states.

>>>>>>

void loop()
{
digitalWrite(ledPin, HIGH);
delay(500);
digitalWrite(ledPin, LOW);
delay(500);
}

>>>>>>

Note that, delay unit is milliseconds, which means we will have LED turned ON for half second then it gets turned OFF for another half second. Thus blinking appearance is achieved through this. If you wish to have different blinking time scale, please change it accordingly.

We write complete code as,

>>>>>>>>>>>>>>>>>>>>>>>

int ledPin = x;

void setup()
{
pinMode(ledPin, OUTPUT);
}

void loop()
{
digitalWrite(ledPin, HIGH);
delay(500);
digitalWrite(ledPin, LOW);
delay(500);
}

>>>>>>>>>>>>>>>>>>>>>>>

============================================

If you still have any doubt, please let me know in the comment section. All the best :)


Related Solutions

1. Write a code that makes the MSP430 blink the red LED and the green LED...
1. Write a code that makes the MSP430 blink the red LED and the green LED at the same time. The two LEDs should be on at the same time and then off at the same time
Using Arduino to blink an LED in morse code. Morse code is used as one of...
Using Arduino to blink an LED in morse code. Morse code is used as one of the methods for communications. It consists of a series of “dit” and “dah” symbols. (i) Develop an Arduino program to produce a Morse code to express the phrase “We are students” using Pin #13 (connect an LED that is in series with a 220-Ω resistor to Pins #13 to view the information sent via the Morse code). Express one “dit” with LED on for...
1. IN C LANGUAGE: Write a code that makes the MSP430 blink the red LED and...
1. IN C LANGUAGE: Write a code that makes the MSP430 blink the red LED and the green LED at the same time. The two LEDs should be on at the same time and then off at the same time
1.write a program for the msp430 to make led 1 blink at 50 percent duty cycle....
1.write a program for the msp430 to make led 1 blink at 50 percent duty cycle. 2 modify the program to make led 1 blink 5 times, make a long pause, then blink 5 more times then stop. The time delays should be carried out in subroutines
1.write a program for the msp430FR6989 to make led 1 blink at 50 percent duty cycle....
1.write a program for the msp430FR6989 to make led 1 blink at 50 percent duty cycle. 2 modify the program to make led 1 blink 5 times, make a long pause, then blink 5 more times then stop. The time delays should be carried out in subroutines
Write a function, named isMultipleOfFive that accepts integer argument. When the function is called, it should...
Write a function, named isMultipleOfFive that accepts integer argument. When the function is called, it should display if the argument "is a multiple of 5" or "is not a multiple of 5".
Java Write a class called Triangle that can be used to represent a triangle. Write a...
Java Write a class called Triangle that can be used to represent a triangle. Write a class called Describe that will interface with the Triangle class The Server • A Triangle will have 3 sides. It will be able to keep track of the number of Triangle objects created. It will also hold the total of the perimeters of all the Triangle objects created. • It will allow a client to create a Triangle, passing in integer values for the...
Write a version of the selection sort algorithm in a function called selectionSort that can be...
Write a version of the selection sort algorithm in a function called selectionSort that can be used to sort a string vector object. Also, write a program to test your algorithm. The program should prompt the user for a series of names. The string zzz should end the input stream. Output the sorted list to the console. *Need answer in C++*
On November 21, 2019, Travis Barker started a new business called Blink-Blink a. Travis deposited Rp....
On November 21, 2019, Travis Barker started a new business called Blink-Blink a. Travis deposited Rp. 500,000,000 in the bank in the name of Blink-Blink b. Blink-Blink In exchange for a building of Rp. 250,000,000 c. Blink-Blink buys studio equipment Rp. 100,000,000 d. Blink-Blink Receives services from the recording studio for Rp. 200,000,000 e. Blink-Blink Paid Rp. 50,000,000 Utilities Rp. 25,000,000, Rp. Electricity 20,000,000 Cleanliness Rp. 5,000,000 f. Blink-Blik Paying Debt to Labels Rp. 125,000,000 g. End of Month Travis...
Write a C program to blink two LEDs connected to Raspberry pi. One must blink at...
Write a C program to blink two LEDs connected to Raspberry pi. One must blink at a rate of 1 Hz and the other at a rate of 2 HZ.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT