i'm having some problems with a stepper motor in my project.
the project should read my keypad and turn the amount of degrees typed both ways.
the problem is that it's only turning one way
please help me
this is my sketch
#include <Stepper.h>
#include <LiquidCrystal.h>
#include <Keypad.h>
const int stepsPerRevolution = 360;
const byte ROWS = 4; //four rows
const byte COLS = 3; //four columns
//define the cymbols on the buttons of the keypads
char hexaKeys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
byte rowPins[ROWS] = {32, 33, 34, 35}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {36, 37, 38}; //connect to the column pinouts of the keypad
LiquidCrystal lcd(27, 26, 25, 24, 23, 22);
Stepper stepper(stepsPerRevolution, 28, 29, 30, 31);
int C = 0;
int B = 0;
int A = 0;
int D = 0;
//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
void setup(){
Serial.begin(9600);
lcd.begin(16, 2);
lcd.print("THE KNEE HEALER");
stepper.setSpeed(20);
}
void loop(){
char dezena = customKeypad.waitForKey();
lcd.setCursor(0,1);
A = dezena * 10;
B = A - 480;
lcd.print(dezena);
char unidade = customKeypad.waitForKey();
lcd.print(unidade);
C = unidade - 48;
D = B + C;
Serial.println(D);
callMotor();
}
void callMotor(){
G = D * 6;
const int F= G;
const int E=-G;
lcd.clear();
lcd.setCursor(0,0);
lcd.print("angulo:");
lcd.print(D);
lcd.setCursor(0,1);
stepper.step(F);
stepper.step(E);
}
sketch_aug16D_funcional3.ino (1.36 KB)