In: Physics
Write a function that can be used to blink an LED when called.
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 :)