//====================================================================================
//STEPPER MOTOR
const int dirPin = 11;
const int stepPin = 12;
const int stepsPerRevolution = 3200;
int delayMicro = 1250;
//====================================================================================
//LCD
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd = LiquidCrystal_I2C(0x27, 16, 2);
//====================================================================================
//KEYPAD
#include <Keypad.h>
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','#','D'}
};
byte rowPins[ROWS] = {9, 8, 7, 6}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {5, 4, 3, 2}; //connect to the column pinouts of the keypad
//Create an object of keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
//====================================================================================
//SENSOR
int S1 = 10;
int y_value=0;
//====================================================================================
int latch,menu;
//====================================================================================
void setup() {
// Initiate the LCD:
lcd.init();
lcd.backlight();
latch = 0;
// Declare pins as Outputs Stepper Motor
pinMode(stepPin, OUTPUT);
pinMode(dirPin, OUTPUT);
lcd.setCursor (0,0);
lcd.print ("COUNTING MACHINE");
lcd.setCursor (0,1);
lcd.print (" PT GEOMED ");
delay (3000);
lcd.clear();
delay (500);
}
void loop() {
char key = keypad.getKey();// Read the key
int count = digitalRead(S1);
//=====================================================
//================BACK TO MENU UTAMA===================
//=====================================================
if (key == 'D' && (latch == 0 || latch == 1 ||latch == 2))
{
menu=0;
latch=0;
y_value=0;
}
//================KLIK A AUTO=============================
if (key == 'A' && latch == 0)
{
lcd.clear();
menu=1;
latch=1;
}
//================KLIK B MANUAL=============================
if (key == 'B' && latch == 0)
{
lcd.clear();
menu=2;
latch=1;
}
//===================MENU UTAMA=======================
if (menu==0)
{
lcd.setCursor(0,0);
lcd.print(" PILIH MENU : ");
lcd.setCursor(0,1);
lcd.print("A>MANUAL B>AUTO");
}
//===================SUBMENU AUTO=====================
if (menu==1)
{
lcd.setCursor(0,0);
lcd.print(" MENGHITUNG... ");
lcd.setCursor(0,1);
lcd.print("JUMLAH :");
lcd.setCursor(9,1);
lcd.print(y_value);
if (count==0){
y_value++;
delay(150);
}
}
//=================SUBMENU MANUAL====================
if (menu==2)
{
lcd.setCursor(0,0);
lcd.print("MASUKKAN JUMLAH ");
lcd.setCursor(0,1);
lcd.print("BARANG : ");
}
//=================STEPPER RUN====================
if (menu==1) {
digitalWrite(dirPin, HIGH);
digitalWrite(stepPin, HIGH);
delayMicroseconds(delayMicro);
digitalWrite(stepPin, LOW);
delayMicroseconds(delayMicro);
}
}