Hello
I'm a newbie to Arduino, this is my first program. The problem is that the program doesn't wait till the input is given. I referred to a few examples but it wasn't helpful. Please point out the mistake done and explain it, it will be really helpful : D
The program is :
/**
* Write a program to accept the delay time and number of times the 13th pin led should blink
* from the user
*/
int dt,num=0,i=1;
const int led=13;
void setup() {
Serial.begin(9600);
pinMode ( led, OUTPUT);
delaytime();// Line 28
ledblink();//Line 34
}
void loop() {
blinking();
}
void blinking()
{
for (;i<=num;i++)
{
digitalWrite(led,HIGH);
delay(dt);
digitalWrite(led,LOW);
delay(dt);
}
if (i==5)
{exit(0);}
}
void delaytime()
{
Serial.println("Enter the delay time ");
if(Serial.available()==0){}
dt=Serial.parseInt();
}
void ledblink()
{
Serial.println("Enter how many times should the led blink");
if ( Serial.available()== 0){}
num=Serial.parseInt();
}
Hello TheMemberFormerlyKnownAsAWOL
Your solution did solve my problem! But the led isn't blinking XC. Can you please explain why we use "while" instead of "if" and why isn't the led blinking?
P.S. Please copy-paste my code and edit it accordingly so that the led blinks and program stop when led blinks according to the user's input data. I'm sorry if this causes you any trouble, but can you please help me?
Moderators are forum members who volunteer to help maintain good order in the forum by moving inappropriately posted topics, deleting spam posts, deleting duplicate accounts and generally keeping the forum tidy.
We also have the ability to suspend users whose behaviour is unacceptable, such as profanity or other offensive language, but that does not happen too much on this forum
There are different moderators for each International section of the forum in order to deal with the different languages used