Does not name any type arduino code

I cant get this code to work at all any help, making a alarm clock with rtc module and using arduino uno


#include <LiquidCrystal_I2C.h >

#include <Ds1302.h>


#include <time.h> //instead of parenthesis () put angle bracket as YouTube description does not allow angle bracket


// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x3F, 16, 2);
#include <Ds1302.h>
int Hour;
int Min;
int pset = 8; // pushbutton for setting alarm
int phour = 9; // pushbutton for hour
int pmin = 10; // pushbutton for minutes
int pexit = 11; // pushbutton for exit of set alarm
int buzzer = 6;
int h;
int m;
int buttonforset = 0; // pushbutton state for setting alarm
int buttonforhour = 0; // pushbutton state for hour
int buttonformin = 0;// pushbutton state for minutes
int buttonforexit = 0; // pushbutton state for exit of set alarm
int activate=0;
time t;

// Init the DS1302
Ds1302 rtc(2, 3, 4);

void setup()
{
 pinMode(pset, INPUT);
 pinMode(phour, INPUT);
 pinMode(pmin, INPUT);
 pinMode(pexit, INPUT);
 // Set the clock to run-mode, and disable the write protection
 rtc.halt(false);
 rtc.writeProtect(false);

 // Setup LCD to 16x2 characters
 lcd.begin();

// The following lines can be commented out to use the values already stored in the DS1302
 //rtc.setDOW(SATURDAY); // Set Day-of-Week to FRIDAY
 //rtc.setTime(10, 0, 0); // Set the time to 12:00:00 (24hr format)
 //rtc.setDate(11, 11, 2017); // Set the date to August 6th, 2010
}

void loop()
{
 if (activate == 0) {

// Display time on the right conrner upper line
 lcd.setCursor(0, 0);
 lcd.print("Time: ");
 lcd.setCursor(6, 0);
 lcd.print(rtc.getTimeStr());
 
 // Display abbreviated Day-of-Week in the lower left corner
 //lcd.setCursor(0, 1);
 //lcd.print(rtc.getDOWStr(FORMAT_SHORT));
 
 // Display date in the lower right corner
 lcd.setCursor(0, 1);
 lcd.print("Date: ");
 lcd.setCursor(6, 1);
 lcd.print(rtc.getDateStr());
 t = rtc.getTime();
 Hour = t.hour;
 Min = t.min;
 buttonforset = digitalRead(pset);
 } // setting button pressed
 if (buttonforset == HIGH) {
 activate =1;
 lcd.clear(); }
 while(activate== 1){
 lcd.setCursor(0,0);
 lcd.print("Set Alarm");
 lcd.setCursor(0,1);
 lcd.print("Hour= ");
 lcd.setCursor(9,1);
 lcd.print("Min= ");
 buttonforhour = digitalRead(phour); // set hour for alarm
 if (buttonforhour == HIGH){
 h++;
 lcd.setCursor(5,1);
 lcd.print(h);
 if (h)23){ 
 h=0;
 lcd.clear(); }
 delay(100); 
 }
 buttonformin = digitalRead(pmin); // set minutes for alarm
 if (buttonformin == HIGH){
 m++;
 lcd.setCursor(13,1);
 lcd.print(m);
 if (m)59){
 m=0; 
 lcd.clear();}
 delay(100); 
 }

lcd.setCursor(5,1);
 lcd.print(h);
 lcd.setCursor(13,1);
 lcd.print(m);
 buttonforexit = digitalRead(pexit); // exit from set alarm mode
 if (buttonforexit == HIGH){
 activate = 0;
 lcd.clear();
   }
 }
 
 if (Hour== h && Min== m) {
 tone(6,400,300);}
 delay (500);
}

did you mean

if (h > 23)

compiled with these 2 fixes

1 Like

@sander12344567213123213
Please apply an autoformat (Arduino IDE Ctrl-T) to your sketch in order to set a correct indentation to the code - and you probably will see that the code has an unbalansed opening { and closing } braces.

Where is the YouTube page you got this from? What version IDE are you running and where did you get your library?

Is it the one that the IDE finds if you type in Ds1302 in the library finder tool by Rafa Couto?
The only library I found that looks like yours seems to have been updated to something else, as has the time library by Michael Margolis and Paul Stoffregen that you're using to hoist RTC readings into time t; isn't even declared as #include <time.h> anymore, but #include <TimeLib.h>

Either I'm doing something wrong (good possibility) or something seems out of date, as the IDE says:

'class Ds1302' has no member named 'getTimeStr'

which the Rafa Couto Ds1302 library doesn't as I browse the .cpp and .h files.

Your comment says: // Set the LCD address to 0x27 for a 16 chars and 2 line display, you have LiquidCrystal_I2C lcd(0x3F, 16, 2); which sets it for address 0x3F.

Hi, @sander12344567213123213
Welcome to the forum.

What model Arduino are you using?
Does your code compile and load?

What IDE verson.
Did you write this code.
If so.
Have you written it in stages.
Have you got code that JUST operates the LCD display?

Thanks Tom.. :smiley: :+1: :coffee: :coffee: :australia:

this is the video im following but cant seem to get it to work

Neither can many of the people in the comments. I see some of the same errors I got. Looks like this YouTube source is more interested in making money off those affiliate Amazon links, as is RinkyDinkElectronics.com trying to sell my information when I go to their site to see what library is used (and I won't agree, sorry, so it remains a mystery to me).

Unfortunately, projects like these seem to be all over YouTube, with broken code, outdated libraries, and little or no support from the YouTuber.

Your best bet is to get a book such as The Arduino Cookbook, 3rd Ed. by Margolis, Jepson and Weldin and learn to use these individually, then write your own code to combine them into what you want to do. I believe there are sections in that book for components such as all the ones you have in your project.

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