hi friends
new to arduino, this is my second code, just going from having stepper motors turn repeatedly ( a code i know works) to having them turn repeatedly after i press a number, in this case "1".
edit** the error is that the motors dont turn - my guess is something in the getKey area. no error messages present.
also, why is "void setup" always empty/what is this for?
thanks
-F
#include <Keypad.h>
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] = {16,17,18,19};
byte colPINS[COLS] = {2,3,4,5};
Keypad keypad = Keypad( makeKeymap(keys), rowPINS, colPINS, ROWS, COLS );
void setup() {
}
void loop()
{
int ENA = 10; //enable stepper 1
int DIR = 11; //direction stepper 1
int PUL = 12; //pulse stepper 1
int ENA2 = 6; //enable stepper 2
int DIR2 = 7; //direction stepper 2
int PUL2 = 8; //pulse stepper 2
// put your main code here, to run repeatedly:
char key = keypad.getKey();
if (key == '1')
{
int rotation = 3200;
int vel = 50;
int vel2 = 200;
for (int i=0; i<rotation; i++) //Forward 5000 steps
{
digitalWrite(DIR,LOW);
digitalWrite(ENA,HIGH);
digitalWrite(PUL,HIGH);
delayMicroseconds(vel);
digitalWrite(PUL,LOW);
delayMicroseconds(vel);
digitalWrite(DIR2,LOW);
digitalWrite(ENA2,HIGH);
digitalWrite(PUL2,HIGH);
delayMicroseconds(vel2);
digitalWrite(PUL2,LOW);
delayMicroseconds(vel2);
}
}
}