//LCD
#include <LiquidCrystal.h>
//*************** LCD hardware
const int rs = A0, en = A1, d4 = A2, d5 = A3, d6 = A4, d7 = A5;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
// key pad
#include <Keypad.h>
// Character to hold key input
char customKey;
// Constants for row and column sizes
const byte ROWS = 4;
const byte COLS = 4;
//***************
// Array to represent keys on keypad
char hexaKeys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
// *************** key board harware Connections to Arduino mega
byte rowPins[ROWS] = {31, 33, 35, 37};
byte colPins[COLS] = {23,25,27,29};
// Create keypad object
Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
//RTC
#include <RTClib.h>
RTC_DS3231 rtc;
//RTC pin in megha, pin 20 -SDA to SDA of RTC , pin 21 is SCL toSCL of RTC. VCC , and GND
char t[32];
char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
// Servo or dc motor speed control
#include <Servo.h>
// define 5 servo motors
Servo servo1;
Servo servo2;
Servo servo3;
Servo servo4;
Servo servo5;
// aurduino pin as Input or Out put assignments withe pin mapping for motor M1, M2 and pwm enable connection in hardware of mega
// driver has M1, M2 , and Enable/Pwm pins
byte pinsOut[] = {22,24,2,26,28,3,30,32,4,34,36,5,38,40,6}; // first bit is left most,22,24,2 motor no 1
void setup() {
//LCD
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// key pad
// no setup
//RTC
// put your setup code here, to run once:
Serial.begin(9600); // to see in serial monitor dont use this Serial.begin if pin 0,1 is used for high or low, in this project it is used
// Serial.begin(115200);
Wire.begin();
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
Serial.flush();
abort();
}
rtc.begin();
rtc.adjust(DateTime(F(__DATE__),F(__TIME__))); // loads from system timeing
// servo motor pins attachaments
// hardware pins are 2,3,4,5,6 of megaa stored in pinout[]
servo1.attach(pinsOut[2]); // hardware pin
servo2.attach(pinsOut[5]); // harware pin will be 3
servo3.attach(pinsOut[8]);
servo4.attach(pinsOut[11]);
servo5.attach(pinsOut[14]);
}
void loop() {
// RTC output
DateTime now = rtc.now();
sprintf(t, "%02d:%02d:%02d:%s", now.day(),now.month() , now.year(),daysOfTheWeek[now.dayOfTheWeek()]);
// key pad output
// if custom key to caputure no delay should be there
customKey = customKeypad.getKey(); // should be looped here else will not wait
if (customKey) {
Serial.println(customKey);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(t);
lcd.setCursor(0, 1);
lcd.print(customKey);
}
// move the servo motors now to different positions
/*"0°" (~1 ms pulse)
"90°” (~1.5 ms pulse)
"180°" (~2 ms pulse) */
servo1.write(56); // 0 degree
servo2.write(45); // 0 degree
servo3.write(90); // 0 degree
servo4.write(135); // 0 degree
servo5.write(180); // 0 degree
delay(2000);
servo1.write(0); // 0 degree
servo2.write(0); // 0 degree
servo3.write(0); // 0 degree
servo4.write(0); // 0 degree
servo5.write(0); // 0 degree
delay(2000);
servo1.write(7); // 0 degree
servo2.write(135); // 0 degree
servo3.write(90); // 0 degree
servo4.write(45); // 0 degree
servo5.write(0); // 0 degree
}