Hello
What I want is for the program to print "Number of coils?" and then receive input. Then take input and then do something with it. I have a (some what) working program that lacks the initial question "Number of Coils". It's pretty ugly but works. here is what I have so far.
/* @file MyAutoCoil
|| @version 6.0
|| @author Submicro
|| @contact submicro68@gmail.com
||
|| @description
|| | Asks for user input then
|| | Makes coils with stepper motors
|| | Still incomplete, needs alot of work.
|| | At least it WORKS!!
|| #
*/
#include <Wire.h> //==========================
#include <Keypad.h> //===== Included Libs ====
#include <Stepper.h> //=======================
#include <LiquidCrystal_I2C.h> //=============
//======initialize Variables_=======
byte numberOfCoils = 0; //==========
long totalNumberOfSteps = 0; //=====
const int stepsPerCoil = 800; //====
const byte enablePin0 = 38; //======
const byte enablePin1 = 56; //======
byte coils; //======================
//=======_setup keypad library ============
const byte ROWS = 4; // ==four row ========
const byte COLS = 3; // ==three columns ===
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
byte rowPins[ROWS] = {47, 37, 39, 43}; // ==== connect to the row pinouts of the keypad ====
byte colPins[COLS] = {45, 32, 41}; // ====== connect to the column pinouts of the keypad ===
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS ); // ==========
LiquidCrystal_I2C lcd(0x27,20,4); // ========= initialize the liquid crystal library ==
Stepper myStepper0(stepsPerCoil, 54, 55); // ==== initialize the stepper library ======
Stepper myStepper1(stepsPerCoil, 60, 61); // ==== initialize the stepper library ======
byte ledPin = 13;
boolean blink = false; //==Set initial state==
boolean ledPin_state; //======================
void setup(){
lcd.init(); //================ Initialize LCD ======
lcd.backlight(); //========= Turn on backlight =====
lcd.setCursor(0, 1); //====== Cursor Position ======
pinMode(ledPin, OUTPUT); //==== Sets the digital pin as output.====
pinMode(enablePin0, OUTPUT); //=========== Active low =============
pinMode(enablePin1, OUTPUT); //=========== Active low =============
digitalWrite(ledPin, HIGH); //========== Turn the LED on ==========
digitalWrite(enablePin0, HIGH); //== Set high untill needed (it's active low) ==
digitalWrite(enablePin1, HIGH); //== Set high untill needed (it's active low) ==
ledPin_state = digitalRead(ledPin); // Store initial LED state. HIGH when LED is on.
keypad.addEventListener(keypadEvent); // Add an event listener for this keypad
}
void loop()
{
char key = keypad.getKey(); //== Check the keypad for pressed keys ==
}
// ======================================
// ======= Handle keypad events =========
// === This is clumsy and very sloppy ===
// ======= Needs ALOT of work!! =========
// ======================================
void keypadEvent(KeypadEvent key){
switch (keypad.getState()){
case PRESSED:
if (key == '1') {
numberOfCoils = 1;
lcd.init();
lcd.print("1 Coil");
}
if (key == '2') {
numberOfCoils = 2;
lcd.init();
lcd.print("2 Coils");
}
if (key == '3') {
numberOfCoils = 3;
lcd.init();
lcd.print("3 Coils");
}
if (key == '4') {
numberOfCoils = 4;
lcd.init();
lcd.print("4 Coils");
}
if (key == '5') {
numberOfCoils = 5;
lcd.init();
lcd.print("5 Coils");
}
if (key == '6') {
numberOfCoils = 6;
lcd.init();
lcd.print("6 Coils");
}
if (key == '7') {
numberOfCoils = 7;
lcd.init();
lcd.print("7 Coils");
}
if (key == '8') {
numberOfCoils = 8;
lcd.init();
lcd.print("8 Coils");
}
if (key == '9') {
numberOfCoils = 9;
lcd.init();
lcd.print("9 Coils");
}
break;
case HOLD:
if (key == '#') {
totalNumberOfSteps = (numberOfCoils * stepsPerCoil);
lcd.init();
lcd.home();
lcd.print("Total number of ");
lcd.setCursor(0,1);
lcd.print("steps is ");
lcd.print(totalNumberOfSteps);
lcd.setCursor(0,2);
lcd.print("Press * key to begin");
}
break;
case RELEASED:
if (key == '*')
{
digitalWrite(enablePin0, LOW); // =======================================
myStepper0.setSpeed(200); // ====== Set the speed to rpm needed: ========
myStepper0.step(totalNumberOfSteps); // ===Get to steppin brother!! =====
lcd.clear(); // ================== Clear the screen... ==================
}
}
}