INSERT A VARIABLE.

i've try this program

//declare variables for the motor pins
int motorPin1 = 2; // Blue - 28BYJ48 pin 1
int motorPin2 = 3; // Pink - 28BYJ48 pin 2
int motorPin3 = 4; // Yellow - 28BYJ48 pin 3
int motorPin4 = 5; // Orange - 28BYJ48 pin 4
// Red - 28BYJ48 pin 5 (VCC)

void setup() {
pinMode(motorPin1, OUTPUT);
pinMode(motorPin2, OUTPUT);
pinMode(motorPin3, OUTPUT);
pinMode(motorPin4, OUTPUT);

digitalWrite(motorPin1,LOW);
digitalWrite(motorPin2,LOW);
digitalWrite(motorPin3,LOW);
digitalWrite(motorPin4,LOW);
int leitura; //define a variavel leitura que corresponde a uma letra o teclado
Serial.begin(9600);

}

void loop(){
int x=1;
int i=0;
x = Serial.read();
if (x > 2 ) {
for (i=0; i>65; i++) {
digitalWrite(motorPin1,LOW);
digitalWrite(motorPin4,HIGH);
delay(x);

digitalWrite(motorPin4,HIGH);
digitalWrite(motorPin3,HIGH);
delay(x);

digitalWrite(motorPin4,LOW);
digitalWrite(motorPin3,HIGH);

delay(x);

digitalWrite(motorPin4,LOW);
digitalWrite(motorPin2,HIGH);
digitalWrite(motorPin3,HIGH);
delay(x);

digitalWrite(motorPin2,HIGH);
digitalWrite(motorPin3,LOW);
delay(x);

digitalWrite(motorPin2,HIGH);
digitalWrite(motorPin1,HIGH);
delay(x);

digitalWrite(motorPin2,LOW);
digitalWrite(motorPin1,HIGH);
delay(x);

digitalWrite(motorPin1,HIGH);
digitalWrite(motorPin4,HIGH);
delay(x);
} }

}

but it does not work as it should, I want to make a program that the delay I enter on the keyboard and make the "for" routine 64 times ( this is my PWM, is for a stepper motor) , using the variable that I enter (I control the frequency controlling the variable). and when I run it I insert the variable, nothing happens. SOMEONE can help?

What range of values do you expect to get for x and values do you actually get when you read the serial input, especially as you do not check before reading it that there is something to be read.

Subtle hint...

 for (i=0; i>65; i++) {

read up on using serial.

  1. Most 99.9999% of the time x will be -1 the result of reading when there is no data.

  2. If you type 1 in the serial monitor serial.read() will return 48(the vaule used to represent the char '1') and then 13(cr) and then 10 (LF) read up on ascii

Mark