system
December 25, 2012, 7:55pm
1
here is the problem.
the var i will not increase.
my out put via Serial.
DIR= 1 steps= 15
15151515151515151515151515151515151515151515151515151515151515151515151515151515
Here is the code.
void setup(){
pinMode(7,OUTPUT);
pinMode(8,OUTPUT);
pinMode(9,OUTPUT);
Serial.begin(9600);
}
void loop(){
step(true,15);
}
void step(boolean dir,int steps){
digitalWrite(8,dir); // set the direction via call dir
digitalWrite(7,HIGH); // Set sleep on
delay(50);
Serial.print("DIR= ");
Serial.print(dir);
Serial.print(" steps= ");
Serial.println(steps);
for(int i=0;i = steps;i++){
//CHSW(); // take time to check the button
digitalWrite(9, HIGH);
delayMicroseconds(90);
digitalWrite(9, LOW);
delayMicroseconds(90);
Serial.print(i);
} // END for(int i=0;i = steps;i++)
digitalWrite(7,LOW);
} //END step(boolean dir,int steps)
Thanks for the help
system
December 25, 2012, 7:57pm
2
i = steps
That's an assignment, not a comparison.
Rest assured, for loops do work.
(It's a kind of comparison; the assignment is done and the outcome is tested zero/non-zero)
system
December 25, 2012, 8:04pm
3
Ok.
It would have been nice to see what it should have been.
i changed it to this.
for(int i=0;i <= steps;i++){
It works.
Thank you
marco_c
December 25, 2012, 8:05pm
4
for(int i=0;i = steps;i++){
should be
for(int i=0;i < steps;i++){
if you have declared steps[15] as an array
system
December 25, 2012, 8:08pm
5
steps clearly isn't an array, but if you want fifteen steps, then yes, <= is incorrect.
system
December 25, 2012, 10:51pm
6
steps is not an array.
steps = 15;
for (int i = 0 ; i <= steps ; i++ ) {
// for (start at 0; if i equals/same DO IT; add 1 to i) {
DO-IT();
}
This is how I understand it.
I will be making a different post. Its the original problem....
Dave
system
December 26, 2012, 1:14am
7
// for (start at 0; if i equals/same DO IT; add 1 to i) {
The middle clause is a while clause. Execute the body of the for statement while i is less than or equal steps.
system
December 26, 2012, 2:41am
8
thank you PaulS,
I did try <= >= != and so on. Here is what i found just minutes ago.
I changed for (int i=0;i<=steps;i++){
to a for(int i=0;i<=TheDelay;i++){
and it works great.
this was just a test but it worked. Is steps a reserved word? it did not turn red.
*TheDelay = 90
Any insight on why?
thanks
system
December 26, 2012, 12:52pm
9
Is steps a reserved word?
No.
*TheDelay = 90
What does this mean? How is TheDelay declared?
Any insight on why?
On why what? You changed the code you initially posted, but haven't shown us the changed code. You can't reasonably expect us yo answer questions about code we can't see, can you?
system
December 26, 2012, 1:49pm
10
Thanks for the response PaulS.
*TheDelay = 90 was not in a code window. So its not code. I was letting viewers know TheDelay equaled 90.
as for not showing the changes. Posted on: December 25, 2012, 03:04:40 PM
for(int i=0;i <= steps;i++){
Then i stated i was having a different problem. (well it was the first problem i did not post until now but was the main problem.)
I will be making a different post.
So i hope this clears thing up for you.
This question was answered.