Robin2:
In Reply #5 you said you had problems when trying my code. That is the code I want you to post - the exact code that you tried.
…R
ok Robin2:
this code does not depend on accelstepper library ,rather depends on controlling the dealyMicroseconds() time between (the high & low)modes of the step pin:
transforming equations are at function [stepper()]
Thanks
#include <Stepper.h>
#include <Keypad.h>
#include <SPI.h>
#include <LiquidCrystal.h>
#include <AccelStepper.h>
LiquidCrystal lcd(8,9,4,5,6,7);
///////////////////////////////
//accelstepper
int dirpin = 18;
int steppin = 19;
int enable = 17;
AccelStepper mystepper(1, steppin, dirpin);
// int steps_per_sec;
float inverse_sps;
float rps;
// float x=0;
/////////////////////////////////
int keypad_pin = A0;
int keypad_value = 0;
int keypad_value_old = 0;
char btn_push;
byte mainMenuPage = 1;
byte mainMenuPageOld = 1;
byte mainMenuTotal = 2;
//////////////////////////////////////////////////
int Q=0; // volume flow_rate
int V=0; // total volume
float rpm=0; // rpm of stepper motor
char key;
long sum=0;
float ID=0;
const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution
int stepCount = 0; // number of steps the motor has taken
//Stepper myStepper(stepsPerRevolution, 11, 12, 13, 14);
// for your motor
//void keypad_set_up();
int get_sum();
void Main_Menu_Display();
void main_menu_setup();
void Main_Menu_Btn();
void main_menu_loop();
void Automatic();
void Manual();
char ReadKeypad();
void WaitBtnRelease();
const byte rows=4;
const byte cols=4;
char keys[rows][cols] =
{
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowpins[rows] = {32,34,36,38};
byte colpins[cols] = {24,26,28,30};
Keypad keypad = Keypad(makeKeymap(keys), rowpins, colpins, rows, cols);
int stepper();
void Automatic()
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Enter, Tube ID");
sum=0;
while(ReadKeypad()!= 'S')
{
//Insert Task for Menu A here
lcd.setCursor(8,1);
lcd.print("mm");
ID=get_sum();
//***************** هااااااااااااااااااااااام
//if(int(key)=='C');
//return ????? امسح الارقام وابدأ من تاني؟
// ازاي انتقل للبعديها؟
}
WaitBtnRelease();
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Enter,Total Volume");
sum=0;
while(ReadKeypad()!= 'S')
{
//Insert Task for automatoc-->total volume here
lcd.setCursor(8,1);
lcd.print("ml");
V=get_sum();
//*****************
//if(int(key)=='C');
//return ?????
}
WaitBtnRelease();
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Enter,Flow_Rate");
sum=0;
while(ReadKeypad()!= 'S')
{
//Insert Task for automatic--> flow_rate here
lcd.setCursor(8,1);
lcd.print("ml/min");
Q=get_sum();
//*****************
//if(int(key)=='C');
//return ?????
// if (ReadKeypad()=='D')
// {
// Q=Q-5;
// }
// else if (ReadKeypad()=='U')
// {
// Q=Q+5;
// }
}
WaitBtnRelease();
stepper();
}
void Manual()
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Enter, Tube ID");
sum=0;
while(ReadKeypad()!= 'S')
{
//Insert Task for Manual here
lcd.setCursor(8,1);
lcd.print("mm");
ID=get_sum();
//***************** هااااااااااااااااااااااام
//if(int(key)=='C');
//return ????? امسح الارقام وابدأ من تاني؟
// ازاي انتقل للبعديها؟
}
WaitBtnRelease();
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Enter,Flow_Rate");
sum=0;
while(ReadKeypad()!= 'S')
{
//Insert Task for automatic--> flow_rate here
lcd.setCursor(8,1);
lcd.print("ml/min");
Q=get_sum();
//*****************
//if(int(key)=='C');
//return ?????
// if (ReadKeypad()=='D')
// {
// Q=Q-5;
// }
// else if (ReadKeypad()=='U')
// {
// Q=Q+5;
// }
}
WaitBtnRelease();
stepper();
}
void Main_Menu_Display()
{
lcd.clear();
lcd.setCursor(0,0);
switch (mainMenuPage)
{
case 1:
lcd.print("1.Automatic");
break;
case 2:
lcd.print("2. Manual");
break;
}
}
void Main_Menu_Btn()
{
WaitBtnRelease();
if(btn_push == 'D')
{
mainMenuPage++;
if(mainMenuPage > mainMenuTotal)
mainMenuPage = 1;
}
else if(btn_push == 'U')
{
mainMenuPage--;
if(mainMenuPage == 0)
mainMenuPage = mainMenuTotal;
}
if(mainMenuPage != mainMenuPageOld) //only update display when page change
{
Main_Menu_Display();
mainMenuPageOld = mainMenuPage;
}
}
char ReadKeypad()
{
/* Keypad button analog Value
no button pressed 1023
select 638
left 407
down 253
up 96
right 0
*/
keypad_value = analogRead(keypad_pin);
if(keypad_value < 50)
return 'R';
else if(keypad_value < 110)
return 'U';
else if(keypad_value < 300)
return 'D';
else if(keypad_value < 500)
return 'L';
else if(keypad_value < 750)
return 'S';
else
return 'N';
}
void WaitBtnRelease()
{
while( analogRead(keypad_pin) < 800){}
}
///////////////////////////////////////
//void keypad_set_up()
//{
// put your setup code here, to run once:
// lcd.setCursor(8,1);
// lcd.print("ml");
//}
//********* check int loop
int get_sum()
{
// put your main code here, to run repeatedly:
lcd.setCursor(0,1);
// while(keypad.getKey()==0)
delay(10);
key=keypad.getKey();
if(key>47&&key<58)
// if(key!='A'&&key!='B'&&key!='C'&&key!='D')
{
Serial.println(key);
sum=sum*10+(key-48);
lcd.print(sum);
Serial.println(sum);
}
return sum;
}
int stepper()
{
rpm=Q/(.009474140097*ID*ID);
rps=rpm/60;
inverse_sps=1/((3200*rps)/1000000); //inverse of steps per second-->steps per sec = 3200*rps
// x=inverse_sps;
// Serial.println(steps_per_sec);
}
void setup()
{
pinMode(dirpin, OUTPUT);
pinMode(steppin, OUTPUT);
digitalWrite(enable, HIGH);
digitalWrite(dirpin, HIGH); // Set the direction.
stepper;
digitalWrite(enable,HIGH);
// mystepper.setMaxSpeed(37300);
//mystepper.setSpeed(steps_per_sec);
lcd.begin(16,2); //Initialize a 2x16 type LCD
Main_Menu_Display();
//delay(1000);
Serial.begin(9600);
Serial.println("start,,,,,,");
}
void loop()
{
btn_push = ReadKeypad();
Main_Menu_Btn();
if(btn_push == 'S')//enter selected menu
{
WaitBtnRelease();
switch (mainMenuPage)
{
case 1:
Automatic();
break;
case 2:
Manual();
break;
}
Main_Menu_Display();
WaitBtnRelease();
}
digitalWrite(steppin, LOW); // This LOW to HIGH change is what creates t
delayMicroseconds(27);
//delayMicroseconds(inverse_sps/2);
digitalWrite(steppin, HIGH);
// delayMicroseconds(inverse_sps/2);
delayMicroseconds(27); // This delay time is close to top speed for thi
// particular motor. Any faster the motor stalls.
//delay(100);
}//--------------- End of loop() loop ---------------------