#include <LiquidCrystal.h>
#include <Keypad.h>
#include <Stepper.h>
LiquidCrystal lcd_1(1, 2, 4, 5, 6, 7);
//Stepper(steps, pin1, pin2) //For Intializing the motors
//Stepper(steps, pin1, pin2, pin3, pin4) //For Intializing the motors
const byte numRows= 4; //number of rows on the keypad
const byte numCols= 4; //number of columns on the keypad
char keymap[numRows][numCols]=
{
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
//Code that shows the the keypad connections to the arduino terminals
byte rowPins[numRows] = {A0,A1,A2,A3}; //Rows 0 to 3
byte colPins[numCols]= {13,12,11,10}; //Columns 0 to 3
//coilwinding variables
char turns;
int lcdRow = 0;
int totalTurns;
int cnt = 0;
String windings;
//initializes an instance of the Keypad class
Keypad myKeypad= Keypad(makeKeymap(keymap), rowPins, colPins, numRows, numCols);
void setup() {
lcd_1.begin(16, 2); // Set up the number of columns and rows on the LCD.
lcd_1.setCursor(5, 0);
lcd_1.print("Welcome");
lcd_1.setCursor(3, 1);
lcd_1.print("Team Tech");
delay(2000); // Wait for 2000 millisecond(s)
lcd_1.setCursor(5, 0);
lcd_1.print("Presents");
lcd_1.setCursor(3, 1);
lcd_1.print("Coil Winder");
delay(2000); // Wait for 2000 millisecond(s)
lcd_1.clear();
lcd_1.setCursor(5, 0);
lcd_1.print("by SDL");
delay(2000); // Wait for 2000 millisecond(s)
lcd_1.clear();
lcd_1.setCursor(0, 0);
lcd_1.print("Press * To Begin");
delay(2000); // Wait for 2000 millisecond(s)
}
void loop() {
char keypressed = myKeypad.getKey();
char keyWait;
if (keypressed == '*')
{
switch(keypressed)
{
case'*':
lcd_1.clear();
lcd_1.setCursor(0, 0);
lcd_1.print("Set no. Turns");
lcd_1.setCursor(0, 1);
lcd_1.print("Press # to Ent");
delay(3000);
lcd_1.clear();
lcd_1.setCursor(0, 0);
lcd_1.print("Turns:");
while (keyWait !='#' || cnt < 5)
{
keyWait = myKeypad.waitForKey();
if(keyWait !='#')
{
turns = keyWait;
//lcd_1.print(turns);
lcd_1.setCursor(++lcdRow,1);
lcd_1.print(turns);
windings = windings + turns;
}
++cnt;
}
totalTurns = windings.toInt();
lcd_1.clear();
lcd_1.setCursor(0, 0);
lcd_1.print("KW = ");
lcd_1.print(keyWait);
delay(3000);
lcd_1.clear();
lcd_1.setCursor(0, 0);
lcd_1.print("TotTurns: ");
lcd_1.print((totalTurns));
lcd_1.setCursor(0, 1);
lcd_1.print("Start Wrap?");
lcd_1.print("Start Wrap?");
break;
case'#':
lcd_1.setCursor(0,0);
lcd_1.print("Turns=");
lcd_1.print(int(totalTurns));
break;
default:
lcd_1.clear();
lcd_1.setCursor(0, 0);
lcd_1.print("Start Wrap?(Y/N)");
}
}
}