Need Help with programming this code

I want to work of this code to somehow make an alarm clock, I have all the pieces but have no idea where to start.. Please if anyone can help

Thanks

The Code:

// Include Libraries
#include "Arduino.h"
#include "Buzzer.h"
#include "LiquidCrystal_PCF8574.h"
#include "Button.h"
#include "Wire.h"
#include "RTClib.h"

// Pin Definitions
#define BUZZER_PIN_SIG 2
#define PUSHBUTTON_1_PIN_2 3
#define PUSHBUTTON_2_PIN_2 4
#define PUSHBUTTON_3_PIN_2 5
#define PUSHBUTTON_4_PIN_2 6

// Global variables and defines
// There are several different versions of the LCD I2C adapter, each might have a different address.
// Try the given addresses by Un/commenting the following rows until LCD works follow the serial monitor prints.
// To find your LCD address go to: Arduino Playground - I2cScanner and run example.
#define LCD_ADDRESS 0x3F
//#define LCD_ADDRESS 0x27
// Define LCD characteristics
#define LCD_ROWS 2
#define LCD_COLUMNS 16
#define SCROLL_DELAY 150
#define BACKLIGHT 255
// object initialization
Buzzer buzzer(BUZZER_PIN_SIG);
LiquidCrystal_PCF8574 lcdI2C;
Button pushButton_1(PUSHBUTTON_1_PIN_2);
Button pushButton_2(PUSHBUTTON_2_PIN_2);
Button pushButton_3(PUSHBUTTON_3_PIN_2);
Button pushButton_4(PUSHBUTTON_4_PIN_2);
RTC_DS3231 rtcDS;

// define vars for testing menu
const int timeout = 10000; //define timeout of 10 sec
char menuOption = 0;
long time0;

// Setup the essentials for your circuit to work. It runs first every time your circuit is powered with electricity.
void setup()
{
// Setup Serial which is useful for debugging
// Use the Serial Monitor to view printed messages
Serial.begin(9600);
while (!Serial) ; // wait for serial port to connect. Needed for native USB
Serial.println("start");

// initialize the lcd
lcdI2C.begin(LCD_COLUMNS, LCD_ROWS, LCD_ADDRESS, BACKLIGHT); 
pushButton_1.init();
pushButton_2.init();
pushButton_3.init();
pushButton_4.init();
if (! rtcDS.begin()) {
Serial.println("Couldn't find RTC");
while (1);
}
if (rtcDS.lostPower()) {
Serial.println("RTC lost power, lets set the time!");
// following line sets the RTC to the date & time this sketch was compiled
rtcDS.adjust(DateTime(F(__DATE__), F(__TIME__)));
// This line sets the RTC with an explicit date & time, for example to set
// January 21, 2014 at 3am you would call:
// rtcDS.adjust(DateTime(2014, 1, 21, 3, 0, 0));
}
menuOption = menu();

}

// Main logic of your circuit. It defines the interaction between the components you selected. After setup, it runs over and over again, in an eternal loop.
void loop()
{

if(menuOption == '1') {
// Buzzer - Test Code
// The buzzer will turn on and off for 500ms (0.5 sec)
buzzer.on();       // 1. turns on
delay(500);             // 2. waits 500 milliseconds (0.5 sec). Change the value in the brackets (500) for a longer or shorter delay in milliseconds.
buzzer.off();      // 3. turns off.
delay(500);             // 4. waits 500 milliseconds (0.5 sec). Change the value in the brackets (500) for a longer or shorter delay in milliseconds.
}
else if(menuOption == '2') {
// LCD 16x2 I2C - Test Code
// The LCD Screen will display the text of your choice.
lcdI2C.clear();                          // Clear LCD screen.
lcdI2C.print("  Circuito.io  ");                   // Print print String to LCD on first line
lcdI2C.selectLine(2);                    // Set cursor at the begining of line 2
lcdI2C.print("     Rocks!  ");                   // Print print String to LCD on second line
delay(1000);

}
else if(menuOption == '3') {
// Mini Pushbutton Switch #1 - Test Code
//Read pushbutton state. 
//if button is pressed function will return HIGH (1). if not function will return LOW (0). 
//for debounce funtionality try also pushButton_1.onPress(), .onRelease() and .onChange().
//if debounce is not working properly try changing 'debounceDelay' variable in Button.h
bool pushButton_1Val = pushButton_1.read();
Serial.print(F("Val: ")); Serial.println(pushButton_1Val);

}
else if(menuOption == '4') {
// Mini Pushbutton Switch #2 - Test Code
//Read pushbutton state. 
//if button is pressed function will return HIGH (1). if not function will return LOW (0). 
//for debounce funtionality try also pushButton_2.onPress(), .onRelease() and .onChange().
//if debounce is not working properly try changing 'debounceDelay' variable in Button.h
bool pushButton_2Val = pushButton_2.read();
Serial.print(F("Val: ")); Serial.println(pushButton_2Val);

}
else if(menuOption == '5') {
// Mini Pushbutton Switch #3 - Test Code
//Read pushbutton state. 
//if button is pressed function will return HIGH (1). if not function will return LOW (0). 
//for debounce funtionality try also pushButton_3.onPress(), .onRelease() and .onChange().
//if debounce is not working properly try changing 'debounceDelay' variable in Button.h
bool pushButton_3Val = pushButton_3.read();
Serial.print(F("Val: ")); Serial.println(pushButton_3Val);

}
else if(menuOption == '6') {
// Mini Pushbutton Switch #4 - Test Code
//Read pushbutton state. 
//if button is pressed function will return HIGH (1). if not function will return LOW (0). 
//for debounce funtionality try also pushButton_4.onPress(), .onRelease() and .onChange().
//if debounce is not working properly try changing 'debounceDelay' variable in Button.h
bool pushButton_4Val = pushButton_4.read();
Serial.print(F("Val: ")); Serial.println(pushButton_4Val);

}
else if(menuOption == '7') {
// RTC - Real Time Clock - Test Code
//This will display the time and date of the RTC. see RTC.h for more functions such as rtcDS.hour(), rtcDS.month() etc.
DateTime now = rtcDS.now();
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.day(), DEC);
Serial.print('/');
Serial.print(now.year(), DEC);
Serial.print("  ");
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();
delay(1000);
}

if (millis() - time0 > timeout)
{
    menuOption = menu();
}

}

// Menu function for selecting the components to be tested
// Follow serial monitor for instrcutions
char menu()
{

Serial.println(F("\nWhich component would you like to test?"));
Serial.println(F("(1) Buzzer"));
Serial.println(F("(2) LCD 16x2 I2C"));
Serial.println(F("(3) Mini Pushbutton Switch #1"));
Serial.println(F("(4) Mini Pushbutton Switch #2"));
Serial.println(F("(5) Mini Pushbutton Switch #3"));
Serial.println(F("(6) Mini Pushbutton Switch #4"));
Serial.println(F("(7) RTC - Real Time Clock"));
Serial.println(F("(menu) send anything else or press on board reset button\n"));
while (!Serial.available());

// Read data from serial monitor if received
while (Serial.available()) 
{
    char c = Serial.read();
    if (isAlphaNumeric(c)) 
    {   
        
        if(c == '1') 
			Serial.println(F("Now Testing Buzzer"));
		else if(c == '2') 
			Serial.println(F("Now Testing LCD 16x2 I2C"));
		else if(c == '3') 
			Serial.println(F("Now Testing Mini Pushbutton Switch #1"));
		else if(c == '4') 
			Serial.println(F("Now Testing Mini Pushbutton Switch #2"));
		else if(c == '5') 
			Serial.println(F("Now Testing Mini Pushbutton Switch #3"));
		else if(c == '6') 
			Serial.println(F("Now Testing Mini Pushbutton Switch #4"));
		else if(c == '7') 
			Serial.println(F("Now Testing RTC - Real Time Clock"));
        else
        {
            Serial.println(F("illegal input!"));
            return 0;
        }
        time0 = millis();
        return c;
    }
}

}

Please start by reading How to get the best out of this forum and add code tags to your posted code to make it easier to read and copy

What programming/Arduino/electronics experience do you have ?

not a lot when I'm on my own

Did you compile the sketch?

not sure what you mean by that.

You should post code by using code-tags
There is an automatic function for doing this in the Arduino-IDE
just three steps

  1. press Ctrl-T for autoformatting your code
  2. do a rightclick with the mouse and choose "copy for forum"
  3. paste clipboard into write-window of a posting

you should be able to the steps described above

To say it very clear: There are some pre-requisites you as a new user must fullfill to get detailed help

And I guess you are able to read this article

Of course you can go on whining and beggin "please can somebody help" . Though this will take days with just repeated answers of
How to get the best out of this forum.

best regards Stefan

Do not try to do it all at once. Do one smaller part, get it working and only then add another part.

Do your self a favor and install and use the hd44780 library for your I2C LCD. The library will automatically determine the I2C address and pin mapping. The library is available through the IDE library manager.

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