Hi,
I am new to this forum, i have programing question i need help with,
i found this code. i am typing on the keypad the decimal number and making the stepper moves assigned decimal number . and everything works fine ( maybe it need fixing some keypad coding ) , what i need is i want to add one more stepper motor and do same think with second motor and when i done with it i want to go back previous motor, i don't need both motor working same time just need to change motors using one keypad and lcd,
i want program says select motorA or MotorB ,then i want to select A , do the code then go back select B do the code .
and also is it possible to keep track when i go back motor A or B their current position or it has to reset 0.
thank you for your passion to read and any help appreciated.
#include <AccelStepper.h> // AccelStepper Library
#include <Keypad.h> // Keypad Library
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
#define I2C_ADDR 0x3F // Add your address here.
#define Rs_pin 0
#define Rw_pin 1
#define En_pin 2
#define BACKLIGHT_PIN 3
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7
LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);
// Global variables
byte index = 0;
char numbers[16]; // Plenty to store a representation of a float
// Keypad Setup
const byte ROWS = 4; // Four Rows
const byte COLS = 4; // Four Columns
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','.'}
};
byte rowPins[ROWS] = {22, 24, 26, 28}; // Arduino pins connected to the row pins of the keypad
byte colPins[COLS] = {31, 33, 35, 37}; // Arduino pins connected to the column pins of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS ); // Keypad Library definition
// AccelStepper Setup
AccelStepper stepper(1, A2, A3); // 1 = Easy Driver interface
// Arduino A2 connected to STEP pin of Easy Driver
// Arduino A3 connected to DIR pin of Easy Driver
static char outstr[15];
void setup(void) {
float len=000.000;
// AccelStepper speed and acceleration setup
stepper.setMaxSpeed(22000);
stepper.setAcceleration(10000);
{
lcd.begin (20,4); // our LCD is a 20x4, change for your LCD if needed
// LCD Backlight ON
lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
lcd.setBacklight(HIGH);
}
}
void loop()
{
char key = keypad.getKey();
if(key != NO_KEY)
lcd.print(key);
{
if(key == 'C')
{
index = 0;
numbers[index] = '\0';
}
else if(key == '.')
{
numbers[index++] = '.';
numbers[index] = '\0';
}
else if(key >= '0' && key <= '9')
{
numbers[index++] = key;
numbers[index] = '\0';
}
else if(key == '#')
{
float len = atof(numbers); // Do whatever you need to with len
dtostrf(len,7, 3, outstr);
lcd.clear();
lcd.setCursor (13,3);
lcd.print(outstr);
stepper.runToNewPosition(len*2032); // 800 steps for 1 cm
index = 0;
numbers[index] = '\0';
}
}
}