#include <Keypad.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include<Servo.h>
Servo motor;
LiquidCrystal_I2C lcd(0x27, 16, 2); // set the LCD address to 0x27 for a 16 chars and 2 line display
int count = 0;
int digit = 0;
long int bags_passed = 0;
long int bags_selected = 0;
#define selector_switch 2
#define led 3
#define sensor 13
const uint8_t ROWS = 4;
const uint8_t COLS = 4;
char keys[ROWS][COLS] = {
{ '1', '2', '3', 'A' },
{ '4', '5', '6', 'B' },
{ '7', '8', '9', 'C' },
{ '*', '0', '#', 'D' }
};
uint8_t colPins[COLS] = { 8, 7, 6, 5 }; // Pins connected to C1, C2, C3, C4
uint8_t rowPins[ROWS] = { 12, 11, 10, 9 }; // Pins connected to R1, R2, R3, R4
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
void setup() {
pinMode(led, OUTPUT);
pinMode(selector_switch, INPUT);
pinMode(sensor, INPUT);
Serial.begin(9600);
motor.attach(3);
motor.write(160);
digitalWrite(led, LOW);
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0); //(column, row)
lcd.print(" Compcare Tech.");
lcd.setCursor(2, 1);
lcd.print("Count = ");
lcd.setCursor(10, 1);
lcd.print(count);
count = 0;
}
void loop() {
if (digitalRead(selector_switch) == LOW) {
int key = keypad.getKey();
if (key != NO_KEY) {
Serial.println(key);
Serial.println(count);
if(0 <= key <= 9){
count = count*10 + key;
key = 0;
Serial.println(count);
}
}
}
// else if (digitalRead(selector_switch) == LOW) {
// if ((bags_selected - bags_passed) > 0) {
// motor.write(60);
// if (digitalRead(sensor) == LOW) {
// bags_passed++;
// lcd.clear();
// lcd.setCursor(0, 0); //(column, row)
// lcd.print("Total BAGs= ");
// lcd.setCursor(11, 0);
// lcd.print(bags_selected);
// lcd.setCursor(0, 1);
// lcd.print("BAGs pass = ");
// lcd.setCursor(11, 1);
// lcd.print(bags_passed);
// main: if (digitalRead(sensor) == HIGH) {
// return;
// }
// else {
// goto main;
// }
// }
// }
// else if ((bags_selected - bags_passed) == 0) {
// motor.write(160);
// lcd.clear();
// lcd.setCursor(0, 0); //(column, row)
// lcd.print("Total BAGs= ");
// lcd.setCursor(11, 0);
// lcd.print(bags_selected);
// lcd.setCursor(0, 1);
// lcd.print("All BAGs Passed");
// digitalWrite(led, HIGH);
// delay(2000);
// }
// count = 0;
// delay(50);
// }
}