Using an RTC, Arduino Mega, LCD, Buttons, and a Stepper motor to operate on a 24 hour clock and dispense 1 time


#include <RTClib.h>
#include <LiquidCrystal.h>

// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
const int stepPin = 6; 
const int dirPin = 7; 
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
 LiquidCrystal lcd(rs, en, d4, d5, d6, d7);


void setup() {
  lcd.begin(16, 2);  // set up the LCD's number of columns and rows:
  lcd.print("Thanks for using me!"); //displays "thanks for using me!"
  delay(1000); //delays for 1s 
  pinMode(stepPin,OUTPUT); 
  pinMode(dirPin,OUTPUT);
  
}
void loop() {
 Stepper();
 LCD();
}
void Stepper() {
   digitalWrite(dirPin,HIGH); // Enables the motor to move in a particular direction
  for(int x = 0; x < 800; x++) {
    digitalWrite(stepPin,HIGH); 
    delayMicroseconds(500); 
    digitalWrite(stepPin,LOW); 
    delayMicroseconds(500); 
  }
  delay(500); // One second delay
}

void LCD() {
  // scroll 13 positions (string length) to the left to move it offscreen left
    for (int positionCounter = 0; positionCounter < 13; positionCounter++) {
      lcd.scrollDisplayLeft();  // scroll one position left:
      delay(350);//waits 350ms
  }
  // scroll 29 positions (string length + display length) to the right to move it offscreen right
  for (int positionCounter = 0; positionCounter < 29; positionCounter++) {
    lcd.scrollDisplayRight(); //scrolls to the right
    delay(350); //waits for 350ms
  }
  //new line
  delay(1000);
  lcd.clear();
  lcd.print("Consult manual for setup."); // Displats "consult manual for setup."  
  for (int positionCounter = 0; positionCounter < 13; positionCounter++) {
    lcd.scrollDisplayLeft();  // scroll one position left:
    delay(350);//waits 350ms
  }
  for (int positionCounter = 0; positionCounter < 29; positionCounter++) {
    lcd.scrollDisplayRight(); //scrolls to the right
    delay(350); //waits for 350ms
  }
//new line
  delay(1000);
  lcd.clear();
  lcd.print("please select time 1: AM");
  for (int positionCounter = 0; positionCounter < 13; positionCounter++) {
    lcd.scrollDisplayLeft();  // scroll one position left:
    delay(350);//waits 350ms
  }
  for (int positionCounter = 0; positionCounter < 29; positionCounter++) {
    lcd.scrollDisplayRight(); //scrolls to the right
    delay(350); //waits for 350ms
  }
//new line
  delay(1000);
  lcd.clear();
  lcd.print("please select time 2: PM");
  for (int positionCounter = 0; positionCounter < 13; positionCounter++) {
    lcd.scrollDisplayLeft();  // scroll one position left:
    delay(350);//waits 350ms
  }
  for (int positionCounter = 0; positionCounter < 29; positionCounter++) {
    lcd.scrollDisplayRight(); //scrolls to the right
    delay(350); //waits for 350ms
  }
  
  
  delay(5000); // delays for 2s 

  

}

I am having trouble integrating the RTC into the code along with the buttons. Like stated in the post I am wanting my motor to turn on at a programmable time which can be set via buttons.

There are many examples of the RTC with the Arduino, consider looking at an alarm clock.

Oh my dear,

there is more missing ... If I am not wrong you have only a number of messages that are scrolled left/right and back with quite a hugh number of delays.

See here on Wokwi:

There is a long way to go ...

Hi @gilshultz: It's 23:25 o'clock at home .. I quit for today ... :wink:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.