not sure if i use correct words in title but here it is;
with given code, i am running a stepper for number of turns. each loop is one full turn.
it is doing what i want from it so far, but with every loop ends stepper is also stop and run again with new loop. it takes only a moment but i prefer it to run smooth.
can i achive it with loop or should i get rid of loop?
int tur = 100;
int mhz = 320;
int ivme = 20; // kaç turda tam hıza ulaşacak
int b = ivme;
#define dirPin 2
#define stepPin 3
#define stepsPerRevolution 200 // tam tur için 200
int a = 0; // kaçıncı turda
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 10, 11, 12, 13);
void setup()
{
lcd.begin(16, 2);
pinMode(stepPin, OUTPUT);
pinMode(dirPin, OUTPUT);
}
void loop()
{
if (a < tur)
{
lcd.begin(0, 0);
lcd.print(a + 1);
// Set the spinning direction clockwise:
digitalWrite(dirPin, LOW); // LOW or HIGH
for (int i = 0; i < stepsPerRevolution; i++)
{
// These four lines result in 1 step:
int dms = mhz + ( b * 16); // ivme katsayısı
digitalWrite(stepPin, HIGH);
delayMicroseconds(dms);
digitalWrite(stepPin, LOW);
delayMicroseconds(dms);
}
if (a < ivme)
{
b--;
}
if ((tur - (a + 1)) < ivme )
{
b++;
}
a++;
}
}
Try to remove the FOR loop and use just the loop provided by the Arduino framework.
Look at the BlinkWithoutDelay example. Use the timer to decide whether you need to control the motor or the LCD or something else. There is no need to update the LCD as often as you need to control the motor. Create different intervals for your functions. In the long run you might want to extend your program. That will be much easier if you continuously run through loop and never stop for delays.
groundFungus:
lcd.begin(0, 0);
What does that do?
it was for picking the place where the numbers will be, replaced it with lcd.setCursor, i got confused at there i guess.
Klaus_K:
Try to remove the FOR loop and use just the loop provided by the Arduino framework.
Look at the BlinkWithoutDelay example. Use the timer to decide whether you need to control the motor or the LCD or something else. There is no need to update the LCD as often as you need to control the motor. Create different intervals for your functions. In the long run you might want to extend your program. That will be much easier if you continuously run through loop and never stop for delays.
i removed the "for" with easiest way i could figure out and it fixed the problem, thanks! but there is another issue now. new code is here;
int spr = 200;
int tur = 150;
int mhz = 80;
int ivme = (2 * spr); // kaç turda tam hıza ulaşacak
int b = ivme ;
#define dirPin 2
#define stepPin 3
//#define stepsPerRevolution 200 // tam tur için 200
int a = 0; // kaçıncı turda
int Rtur = (tur * spr);
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 10, 11, 12, 13);
void setup()
{
lcd.begin(16, 2);
digitalWrite(dirPin, LOW); // LOW or HIGH
pinMode(stepPin, OUTPUT);
pinMode(dirPin, OUTPUT);
}
void loop()
{
if (a < Rtur)
{
lcd.setCursor(0, 1);
lcd.print((a + 1) / spr);
// Set the spinning direction clockwise:
{
// These four lines result in 1 step:
int dms = ( mhz + b ); // ivme katsayısı
digitalWrite(stepPin, HIGH);
delayMicroseconds(dms);
digitalWrite(stepPin, LOW);
delayMicroseconds(dms);
//lcd.setCursor(0, 0);
//lcd.print(dms);
}
if (a < ivme)
{
b--;
}
if ((Rtur - (a + 1)) < ivme )
{
b++;
}
a++;
}
}
the problem with this is it goes slower with the digit increase in screen.
at first i thought there is something in code lower the speed at 10th turn but than i check it for 100th and it's slowed down again.
i think i need to rearrange lcd display also as Klaus said.