hello guys i need write a variable from my keybboard and i dont know how.
int stp = 8;
int dir = 9;
int led1=5;
int i = 0;
int x=35;
void setup()
{
pinMode(stp, OUTPUT);
pinMode(dir, OUTPUT);
//--------------------------------orar---------------------
digitalWrite(dir,HIGH);
if(x<100){
for(i=0;i<=x;i++){
digitalWrite(stp,HIGH);
delay(8);
digitalWrite(stp,LOW);
delay(8);
}}
//----------------------------------trigonometric--------------------------
delay(100);
digitalWrite(dir,LOW);
if(x>100){
for(i=201;i<=400;i++){
digitalWrite(stp,HIGH);
delay(10);
digitalWrite(stp,LOW);
delay(10);
}}
}
void loop()
{
}
that is my code and i need to give a value to x multiple time's without uploading the program more then once thank you.
i need write a variable from my keybboard
We need to be able to read your code. Edit your post, select the code and click the code tags icon (</>) and save the post. That will remove the smileys from your code.
Thanks. Much better, as you can see. Now we can get down to understanding what you want to do.
First, at the moment all of your code is in the setup() function and will run just once. Is that what you want or do you want to prompt the user for the value of x, run using that value then prompt the user again.
If that is not what you want then please explain your requirement.
i want to run once then ask me for a second value then run again and so on that is final version of my code:
int stp = 8;
int dir = 9;
int led1=6;
int led2=5;
int i = 0;
int x=166;
int y=100-x;
int y1=x-100;
int y2=200-x;
void setup()
{ pinMode(led1,OUTPUT);
pinMode(led2,OUTPUT);
pinMode(stp, OUTPUT);
pinMode(dir, OUTPUT);
//--------------------------------trigonometric---------------------
digitalWrite(dir,LOW);
if(x<50){
for(i=0;i<=x;i++){
digitalWrite(stp,HIGH);
delay(8);
digitalWrite(stp,LOW);
delay(8);
} }
if(x<150 && x>100){
for(i=0;i<=y1;i++){
digitalWrite(stp,HIGH);
delay(8);
digitalWrite(stp,LOW);
delay(8);
} }
//----------------------------------orar--------------------------
digitalWrite(dir,HIGH);
if(x>=50 &&x<=100){
for(i=0;i<=y;i++){
digitalWrite(stp,HIGH);
delay(10);
digitalWrite(stp,LOW);
delay(10);
}}
if(x>=150 && x<=200){
for(i=0;i<=y2;i++){
digitalWrite(stp,HIGH);
delay(8);
digitalWrite(stp,LOW);
delay(8);
} }
}
void loop()
{ if(x<50)
{ digitalWrite(led1,HIGH);
digitalWrite(led2,LOW);}
else
{ digitalWrite(led1,LOW);
digitalWrite(led2,LOW);}
if(x>=50 && x<100)
{digitalWrite(led2,HIGH);
digitalWrite(led1,LOW);}
else
{ digitalWrite(led1,LOW);
digitalWrite(led2,LOW);}
if(x>=100 && 150>=x)
{ digitalWrite(led2,HIGH);
digitalWrite(led1,LOW);}
else
{ digitalWrite(led1,LOW);
digitalWrite(led2,LOW);
}
if(x>150 &&x<=200)
{digitalWrite(led1,HIGH);
digitalWrite(led2,LOW);
}
else
{digitalWrite(led1,LOW);
digitalWrite(led2,LOW);
}
}
This is the link to Serial Input Basics
There is simple code to get user input in the tutorial Planning and Implementing a Program
...R