#include "HX711.h"
#include <Keypad.h>
#include <LiquidCrystal.h>
#include <Wire.h>
#include <Servo.h>
HX711 scale;
LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
Servo servo_test;
int potpin = 0; // analog pin used to connect the potentiometer
int val; // variable to read the value from the analog pin
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] = { 31, 33, 35, 37 }; // Pins connected to C1, C2, C3, C4
uint8_t rowPins[ROWS] = { 39, 41, 43, 45 }; // Pins connected to R1, R2, R3, R4
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
void setup() {
Serial.begin(9600);
lcd.home();
servo_test.attach(13); // attach the signal pin of servo to pin9 of arduino
}
void loop() {
char keypressed = keypad.getKey();
if (keypressed != NO_KEY) {
Serial.print(keypressed);
lcd.print(keypressed);
}
val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
val = map(val, 0, 1023, 0, 70 ); // scale it to use it with the servo (value between 0 and 180)
servo_test.write(val); // sets the servo position according to the scaled value
delay(15);
}