int sensor = 26;
int PUL = 23; //define Pulse pin
int DIR = 25; //define Direction pin
void setup() {
pinMode(sensor, INPUT);
Serial.begin(115200);
pinMode (PUL, OUTPUT);
pinMode (DIR, OUTPUT);
}
void loop() {
int sen = digitalRead(sensor);
if (sen == HIGH) {
Serial.println("HIGH");
delay(1000);
for (int i=0; i<500; i++)
{
for( int x=0; x<255; x++){
digitalWrite(DIR,LOW);
digitalWrite(PUL,HIGH);
Serial.print("i = ");
Serial.println(i);
Serial.print("x = ");
Serial.println(x);
delayMicroseconds(x);
digitalWrite(PUL,LOW);
delayMicroseconds(x);
}}
} else if (sen == LOW) {
Serial.println("LOW");
delay(1000);
} else {
Serial.println("ERROR");
}
}
int sensor = 26;
int PUL = 23; //define Pulse pin
int DIR = 25; //define Direction pin
void setup() {
pinMode(sensor, INPUT);
Serial.begin(115200);
pinMode (PUL, OUTPUT);
pinMode (DIR, OUTPUT);
}
void loop() {
int sen = digitalRead(sensor);
if (sen == HIGH) {
Serial.println("HIGH");
delay(1000);
for (int i=0; i<500; i++)
{
for( int x=0; x<255; x++){
digitalWrite(DIR,LOW);
digitalWrite(PUL,HIGH);
Serial.print("i = ");
Serial.println(i);
Serial.print("x = ");
Serial.println(x);
delayMicroseconds(x);
digitalWrite(PUL,LOW);
delayMicroseconds(x);
}}
} else if (sen == LOW) {
Serial.println("LOW");
delay(1000);
} else {
Serial.println("ERROR");
}
}
EDIT
I am trying to nest a FOR loop inside a FOR loop What I want to do is get x to increase with i until x is 255 then I will continue unit i reaches 500. Right now x goes 0-255 and then i increase by 1. I need the value of x to increase along side with i until 255
for (int i=0; i<500; i++) {
for( int x=0; x<255; x++){
digitalWrite(DIR,LOW);
digitalWrite(PUL,HIGH);
Serial.print("i = ");
Serial.println(i);
Serial.print("x = ");
Serial.println(x);
delayMicroseconds(x);
digitalWrite(PUL,LOW);
delayMicroseconds(x); }
}