TimeLib function calls create errors

I compiled some old code and got the error "#include TimeLib.h no such library". So I reinstalled the Time library in the Library manager and that error went away, but now the standard functions, eg, day(), hour(), setTime(), etc., all create errors.

The old library written by Margolis is no longer listed in the libraries, so I assume the one maintained PaulStoffregen (1.6.1) should have these functions. My system has 1.6.1 installed, but I am still getting the errors. Am I missing an intermediate library?

If you were to cut and paste the full error messages into your post, people might have an idea about the nature of the problem.

Same approach works with code, too :wink:

rather than assuming you can directly check it out in the source code (the functions are there)

https://github.com/PaulStoffregen/Time/blob/master/TimeLib.h

OK, have at it.

 1.8.16 (Windows 10), Board: "Arduino Nano, ATmega328P"



Z:\01-Arduino projects\Driveway\dwalarm_display_II\dwalarm_display_II.ino: In function 'void setup()':
dwalarm_display_II:319:4: error: 'setTime' was not declared in this scope
    setTime(set_hr,set_min,set_sec,set_day,set_mon,set_yr + 2000);
    ^~~~~~~
Z:\01-Arduino projects\Driveway\dwalarm_display_II\dwalarm_display_II.ino:319:4: note: suggested alternative: 'DateTime'
    setTime(set_hr,set_min,set_sec,set_day,set_mon,set_yr + 2000);
    ^~~~~~~
    DateTime
dwalarm_display_II:323:4: error: 'setTime' was not declared in this scope
    setTime(12,0,0,01,06,2022) ; // sets the flag
    ^~~~~~~
Z:\01-Arduino projects\Driveway\dwalarm_display_II\dwalarm_display_II.ino:323:4: note: suggested alternative: 'DateTime'
    setTime(12,0,0,01,06,2022) ; // sets the flag
    ^~~~~~~
    DateTime
dwalarm_display_II:326:11: error: 'day' was not declared in this scope
   Today = day() ;
           ^~~
Z:\01-Arduino projects\Driveway\dwalarm_display_II\dwalarm_display_II.ino:326:11: note: suggested alternative: 'play'
   Today = day() ;
           ^~~
           play
Z:\01-Arduino projects\Driveway\dwalarm_display_II\dwalarm_display_II.ino: In function 'void loop()':
dwalarm_display_II:357:14: error: 'now' was not declared in this scope
   times[0] = now() ;
              ^~~
Z:\01-Arduino projects\Driveway\dwalarm_display_II\dwalarm_display_II.ino:357:14: note: suggested alternative: 'pow'
   times[0] = now() ;
              ^~~
              pow
dwalarm_display_II:372:14: error: 'now' was not declared in this scope
   times[0] = now() ;
              ^~~
Z:\01-Arduino projects\Driveway\dwalarm_display_II\dwalarm_display_II.ino:372:14: note: suggested alternative: 'pow'
   times[0] = now() ;
              ^~~
              pow
dwalarm_display_II:396:14: error: 'day' was not declared in this scope
  if(Today != day()) { // is it the next day?
              ^~~
Z:\01-Arduino projects\Driveway\dwalarm_display_II\dwalarm_display_II.ino:396:14: note: suggested alternative: 'play'
  if(Today != day()) { // is it the next day?
              ^~~
              play
dwalarm_display_II:397:6: error: 'hour' was not declared in this scope
   if(hour() == 1) { // is it 01:00?
      ^~~~
Z:\01-Arduino projects\Driveway\dwalarm_display_II\dwalarm_display_II.ino:397:6: note: suggested alternative: 'ouT'
   if(hour() == 1) { // is it 01:00?
      ^~~~
      ouT
dwalarm_display_II:407:6: error: 'setTime' was not declared in this scope
      setTime(set_hr,set_min,set_sec,set_day,set_mon,set_yr + 2000);
      ^~~~~~~
Z:\01-Arduino projects\Driveway\dwalarm_display_II\dwalarm_display_II.ino:407:6: note: suggested alternative: 'DateTime'
      setTime(set_hr,set_min,set_sec,set_day,set_mon,set_yr + 2000);
      ^~~~~~~
      DateTime
Z:\01-Arduino projects\Driveway\dwalarm_display_II\dwalarm_display_II.ino: In function 'void lcd_24hr()':
dwalarm_display_II:541:7: error: 'hour' was not declared in this scope
   if (hour() < 10) lcd.print("0") ;
       ^~~~
Z:\01-Arduino projects\Driveway\dwalarm_display_II\dwalarm_display_II.ino:541:7: note: suggested alternative: 'ouT'
   if (hour() < 10) lcd.print("0") ;
       ^~~~
       ouT
dwalarm_display_II:542:13: error: 'hour' was not declared in this scope
   lcd.print(hour()) ;
             ^~~~
Z:\01-Arduino projects\Driveway\dwalarm_display_II\dwalarm_display_II.ino:542:13: note: suggested alternative: 'ouT'
   lcd.print(hour()) ;
             ^~~~
             ouT
dwalarm_display_II:544:7: error: 'minute' was not declared in this scope
   if (minute() < 10) lcd.print("0") ;
       ^~~~~~
Z:\01-Arduino projects\Driveway\dwalarm_display_II\dwalarm_display_II.ino:544:7: note: suggested alternative: 'N_minute'
   if (minute() < 10) lcd.print("0") ;
       ^~~~~~
       N_minute
dwalarm_display_II:545:13: error: 'minute' was not declared in this scope
   lcd.print(minute()) ;
             ^~~~~~
Z:\01-Arduino projects\Driveway\dwalarm_display_II\dwalarm_display_II.ino:545:13: note: suggested alternative: 'N_minute'
   lcd.print(minute()) ;
             ^~~~~~
             N_minute
dwalarm_display_II:547:7: error: 'second' was not declared in this scope
   if (second() < 10) lcd.print("0") ;
       ^~~~~~
Z:\01-Arduino projects\Driveway\dwalarm_display_II\dwalarm_display_II.ino:547:7: note: suggested alternative: 'N_second'
   if (second() < 10) lcd.print("0") ;
       ^~~~~~
       N_second
dwalarm_display_II:548:13: error: 'second' was not declared in this scope
   lcd.print(second()) ;
             ^~~~~~
Z:\01-Arduino projects\Driveway\dwalarm_display_II\dwalarm_display_II.ino:548:13: note: suggested alternative: 'N_second'
   lcd.print(second()) ;
             ^~~~~~
             N_second
Z:\01-Arduino projects\Driveway\dwalarm_display_II\dwalarm_display_II.ino: In function 'void date_time()':
dwalarm_display_II:553:13: error: 'month' was not declared in this scope
   lcd.print(month()) ;
             ^~~~~
Z:\01-Arduino projects\Driveway\dwalarm_display_II\dwalarm_display_II.ino:553:13: note: suggested alternative: 'N_month'
   lcd.print(month()) ;
             ^~~~~
             N_month
dwalarm_display_II:555:6: error: 'day' was not declared in this scope
   if(day() < 10) lcd.print("0") ;
      ^~~
Z:\01-Arduino projects\Driveway\dwalarm_display_II\dwalarm_display_II.ino:555:6: note: suggested alternative: 'play'
   if(day() < 10) lcd.print("0") ;
      ^~~
      play
dwalarm_display_II:556:13: error: 'day' was not declared in this scope
   lcd.print(day()) ;
             ^~~
Z:\01-Arduino projects\Driveway\dwalarm_display_II\dwalarm_display_II.ino:556:13: note: suggested alternative: 'play'
   lcd.print(day()) ;
             ^~~
             play
dwalarm_display_II:558:13: error: 'year' was not declared in this scope
   lcd.print(year() - 2000) ;
             ^~~~
Z:\01-Arduino projects\Driveway\dwalarm_display_II\dwalarm_display_II.ino:558:13: note: suggested alternative: 'N_year'
   lcd.print(year() - 2000) ;
             ^~~~
             N_year
Z:\01-Arduino projects\Driveway\dwalarm_display_II\dwalarm_display_II.ino: In function 'void new_TOD()':
dwalarm_display_II:608:13: error: 'year' was not declared in this scope
   set_yr  = year() - 2000 ;
             ^~~~
Z:\01-Arduino projects\Driveway\dwalarm_display_II\dwalarm_display_II.ino:608:13: note: suggested alternative: 'N_year'
   set_yr  = year() - 2000 ;
             ^~~~
             N_year
dwalarm_display_II:609:13: error: 'month' was not declared in this scope
   set_mon = month() ;
             ^~~~~
Z:\01-Arduino projects\Driveway\dwalarm_display_II\dwalarm_display_II.ino:609:13: note: suggested alternative: 'N_month'
   set_mon = month() ;
             ^~~~~
             N_month
dwalarm_display_II:610:13: error: 'day' was not declared in this scope
   set_day = day() ;
             ^~~
Z:\01-Arduino projects\Driveway\dwalarm_display_II\dwalarm_display_II.ino:610:13: note: suggested alternative: 'play'
   set_day = day() ;
             ^~~
             play
dwalarm_display_II:611:13: error: 'hour' was not declared in this scope
   set_hr  = hour() ;
             ^~~~
Z:\01-Arduino projects\Driveway\dwalarm_display_II\dwalarm_display_II.ino:611:13: note: suggested alternative: 'ouT'
   set_hr  = hour() ;
             ^~~~
             ouT
dwalarm_display_II:612:13: error: 'minute' was not declared in this scope
   set_min = minute() ;
             ^~~~~~
Z:\01-Arduino projects\Driveway\dwalarm_display_II\dwalarm_display_II.ino:612:13: note: suggested alternative: 'N_minute'
   set_min = minute() ;
             ^~~~~~
             N_minute
dwalarm_display_II:701:5: error: 'setTime' was not declared in this scope
     setTime(set_hr,set_min,0,set_day,set_mon,set_yr + 2000);
     ^~~~~~~
Z:\01-Arduino projects\Driveway\dwalarm_display_II\dwalarm_display_II.ino:701:5: note: suggested alternative: 'DateTime'
     setTime(set_hr,set_min,0,set_day,set_mon,set_yr + 2000);
     ^~~~~~~
     DateTime
Z:\01-Arduino projects\Driveway\dwalarm_display_II\dwalarm_display_II.ino: In function 'void print_line(byte)':
dwalarm_display_II:778:7: error: 'day' was not declared in this scope
    if(day(times[Line]) < 10) lcd.print(" ") ;
       ^~~
Z:\01-Arduino projects\Driveway\dwalarm_display_II\dwalarm_display_II.ino:778:7: note: suggested alternative: 'play'
    if(day(times[Line]) < 10) lcd.print(" ") ;
       ^~~
       play
dwalarm_display_II:779:14: error: 'day' was not declared in this scope
    lcd.print(day(times[Line])) ;
              ^~~
Z:\01-Arduino projects\Driveway\dwalarm_display_II\dwalarm_display_II.ino:779:14: note: suggested alternative: 'play'
    lcd.print(day(times[Line])) ;
              ^~~
              play
dwalarm_display_II:781:7: error: 'hour' was not declared in this scope
    if(hour(times[Line]) < 10) lcd.print("0") ;
       ^~~~
Z:\01-Arduino projects\Driveway\dwalarm_display_II\dwalarm_display_II.ino:781:7: note: suggested alternative: 'ouT'
    if(hour(times[Line]) < 10) lcd.print("0") ;
       ^~~~
       ouT
dwalarm_display_II:782:14: error: 'hour' was not declared in this scope
    lcd.print(hour(times[Line])) ;
              ^~~~
Z:\01-Arduino projects\Driveway\dwalarm_display_II\dwalarm_display_II.ino:782:14: note: suggested alternative: 'ouT'
    lcd.print(hour(times[Line])) ;
              ^~~~
              ouT
dwalarm_display_II:784:7: error: 'minute' was not declared in this scope
    if(minute(times[Line]) < 10) lcd.print("0") ;
       ^~~~~~
Z:\01-Arduino projects\Driveway\dwalarm_display_II\dwalarm_display_II.ino:784:7: note: suggested alternative: 'N_minute'
    if(minute(times[Line]) < 10) lcd.print("0") ;
       ^~~~~~
       N_minute
dwalarm_display_II:785:14: error: 'minute' was not declared in this scope
    lcd.print(minute(times[Line])) ;
              ^~~~~~
Z:\01-Arduino projects\Driveway\dwalarm_display_II\dwalarm_display_II.ino:785:14: note: suggested alternative: 'N_minute'
    lcd.print(minute(times[Line])) ;
              ^~~~~~
              N_minute
exit status 1
'setTime' was not declared in this scope


This report would have more information with
"Show verbose output during compilation"
option enabled in File ->

and the source code ?

Looks like setTime() and day() were not defined in scope.

This works exactly as expected:

#include "TimeLib.h"

tmElements_t te;  //Time elements structure
time_t unixTime; // a time stamp

void setup() {
  Serial.begin(115200);
  // new internal clock setting.
  // convert a date and time into unix time, offset 1970
  te.Second = 0;
  te.Hour = 23; //11 pm
  te.Minute = 0;
  te.Day = 1;
  te.Month = 1;
  te.Year = 2022 - 1970; //Y2K, in seconds = 946684800UL
  unixTime =  makeTime(te);
  Serial.print("Example 1/1/2022 23:00 unixTime = ");
  Serial.println(unixTime);
  setTime(unixTime); //set the current time to the above entered
  // print as date_time
  print_date_time();
  }
void print_date_time() { //easy way to print date and time
  char buf[40];
  sprintf(buf, "%02d/%02d/%4d %02d:%02d:%02d", day(), month(), year(), hour(), minute(), second());
  Serial.println(buf);
}

void loop() {}

J-M-L your code compiles in my IDE. So here's the problem code:

//                 "01234567890123456789"
char this_file[] = "dwalarm_display_II " ;
char descp[] =     "RS485, tone on A0 " ;
char ver[] =       "ver 2.1    5/22/22 " ;
char ver2[] =      "11 is out, 12 is in" ;
char ver3[] =      "relay on pin xx" ;

// ======================================================
// receives low byte x-axis data from "magsensor2.ino"
// ======================================================

// #define DU_V5
 #define DU_gen1
	
 /*  Hardware description +++++++++++++++++++++++++++++++++++++
 *    Nano
 *    LCD 4x20
 *    V5 RS-485 board, D3 is Rx/Tx select on Max485
 *      (D3 low for receive, high for transmit)
 *    5-switch panel [see: getkeys()]
 *    DS-18B20 pullups on digital pins A0/A1/A2
 *    Pin 10 used for tone output
 *    RS485 serial
 *    Remove the charging resistor on RTC
 *    ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++  
 */
 
 //
 byte TxRx = 3 ;      // drives the MAX485 direction
 byte Tone_out = A0 ; // drives the buzzer
 byte relay = A1 ;    // silence relay
 
#define NOTE_B0  31
#define NOTE_C1  33
#define NOTE_CS1 35
#define NOTE_D1  37
#define NOTE_DS1 39
#define NOTE_E1  41
#define NOTE_F1  44
#define NOTE_FS1 46
#define NOTE_G1  49
#define NOTE_GS1 52
#define NOTE_A1  55
#define NOTE_AS1 58
#define NOTE_B1  62
#define NOTE_C2  65
#define NOTE_CS2 69
#define NOTE_D2  73
#define NOTE_DS2 78
#define NOTE_E2  82
#define NOTE_F2  87
#define NOTE_FS2 93
#define NOTE_G2  98
#define NOTE_GS2 104
#define NOTE_A2  110
#define NOTE_AS2 117
#define NOTE_B2  123
#define NOTE_C3  131
#define NOTE_CS3 139
#define NOTE_D3  147
#define NOTE_DS3 156
#define NOTE_E3  165
#define NOTE_F3  175
#define NOTE_FS3 185
#define NOTE_G3  196
#define NOTE_GS3 208
#define NOTE_A3  220
#define NOTE_AS3 233
#define NOTE_B3  247
#define NOTE_C4  262
#define NOTE_CS4 277
#define NOTE_D4  294
#define NOTE_DS4 311
#define NOTE_E4  330
#define NOTE_F4  349
#define NOTE_FS4 370
#define NOTE_G4  392
#define NOTE_GS4 415
#define NOTE_A4  440
#define NOTE_AS4 466
#define NOTE_B4  494
#define NOTE_C5  523
#define NOTE_CS5 554
#define NOTE_D5  587
#define NOTE_DS5 622
#define NOTE_E5  659
#define NOTE_F5  698
#define NOTE_FS5 740
#define NOTE_G5  784
#define NOTE_GS5 831
#define NOTE_A5  880
#define NOTE_AS5 932
#define NOTE_B5  988
#define NOTE_C6  1047
#define NOTE_CS6 1109
#define NOTE_D6  1175
#define NOTE_DS6 1245
#define NOTE_E6  1319
#define NOTE_F6  1397
#define NOTE_FS6 1480
#define NOTE_G6  1568
#define NOTE_GS6 1661
#define NOTE_A6  1760
#define NOTE_AS6 1865
#define NOTE_B6  1976
#define NOTE_C7  2093
#define NOTE_CS7 2217
#define NOTE_D7  2349
#define NOTE_DS7 2489
#define NOTE_E7  2637
#define NOTE_F7  2794
#define NOTE_FS7 2960
#define NOTE_G7  3136
#define NOTE_GS7 3322
#define NOTE_A7  3520
#define NOTE_AS7 3729
#define NOTE_B7  3951
#define NOTE_C8  4186
#define NOTE_CS8 4435
#define NOTE_D8  4699
#define NOTE_DS8 4978
#define REST      0


// change this to make the song slower or faster
int tempo = 140;

// change this to whichever pin you want to use
byte buzzer = A0 ;


unsigned long T_Return ; // clocks when to return to home page

// notes of the melody followed by the duration.
// a 4 means a quarter note, 8 an eighteenth , 16 sixteenth, so on
// !!negative numbers are used to represent dotted notes,
// so -4 means a dotted quarter note, that is, a quarter plus an eighteenth!!

int melody[] = {
  // Cantina BAnd - Star wars 
  // Score available at https://musescore.com/user/6795541/scores/1606876
  NOTE_B4,-4, NOTE_E5,-4, NOTE_B4,-4, NOTE_E5,-4, 
  NOTE_B4,8,  NOTE_E5,-4, NOTE_B4,8, REST,8,  NOTE_AS4,8, NOTE_B4,8, 
} ;

// sizeof gives the number of bytes, each int value is composed of two bytes (16 bits)
// there are two values per note (pitch and duration), so for each note there are four bytes
int notes = sizeof(melody) / sizeof(melody[0]) / 2;

// this calculates the duration of a whole note in ms
int wholenote = (60000 * 2) / tempo;

int divider = 0, noteDuration = 0;

#include <TimeLib.h>
#include <Wire.h>  // supports I2C
// #include <avr/pgmspace.h>  // included in IDE above 1.0
#include <hd44780.h>                       // main hd44780 header
#include <hd44780ioClass/hd44780_I2Cexp.h> // i2c expander i/o class header

// Simple clock here ======================
#include <DS3231_Simple.h>
  // Create a variable to hold the data 
  DateTime RTC;
  DS3231_Simple Clock;
//  #define I2C_ADDR 0x27 
  byte busStatus;
  
int    page_num = 0 ; // start at the base page
byte ln_pntr ;
// unsigned long clock_t ;

int  set_yr ;
int  set_mon ;
int  set_day ;
int  set_hr ;
int  set_min ;
int  set_sec ;
int LINE ;
int CURSOR ;
int page ;

byte Today ;

hd44780_I2Cexp lcd; // declare lcd object: auto locate & config exapander chip

// LCD geometry
const int LCD_COLS = 20;
const int LCD_ROWS = 4;

//  setTime(hr,min,sec,day,month,yr); // 4 digit year
int N_year ;
int N_month ;
int N_day ;
int N_hour ;
int N_minute ;
int N_second ;

int status ;

byte key ;
// key values from get_keys()
const byte UP    = 0x01 ;
const byte DOWN  = 0x02 ;
const byte PAGE  = 0x04 ;
const byte STEP  = 0x08 ;
const byte ENTER = 0x10 ;

int idcheck ;
int idcheck2 ;
const byte click = 5 ; // click interval in msec

unsigned long msec_0 ;
unsigned long msec_1 ;

byte X1=0, X2=0, X3=0, X4=0 ;
boolean Inbound = false ;
boolean Outbound = false ;
byte led = 13 ;
byte iN = 12 ;
byte ouT = 11 ;
byte xss[40] ; // store a long sample of serial data
byte i ;

time_t times[8] ; // holds the in/out times
byte dirs[8] ;    // holds the in/out direction
byte alarm_pntr = 0 ;

// --------------------------------------------------------------------------
// ------------------ Setup ------------------------------------------------
void setup() {
  
  pinMode(relay, OUTPUT) ; // relay driver
	
  pinMode(8, INPUT_PULLUP) ;  // UP
  pinMode(7, INPUT_PULLUP) ;  // Down
  pinMode(6, INPUT_PULLUP) ;  // Page
  pinMode(5, INPUT_PULLUP) ;  // Step
  #ifdef DU_V5
  pinMode(4, INPUT_PULLUP) ;  // Enter/Select
  #else
  pinMode(2, INPUT_PULLUP) ;  // Enter/Select
  #endif
  
  pinMode(3, OUTPUT) ;   // Tx/Rx direction, low for Rx
  digitalWrite(3,LOW) ;  // this unit only receives
  
  pinMode(buzzer, OUTPUT) ; // tone output
  pinMode(TxRx, OUTPUT) ;   // determines MAX485 direction
  
  digitalWrite(TxRx, 0) ;   // puts this unit into receive mode

  pinMode(iN, INPUT_PULLUP) ;   // (12) if LOW, an inbound is printed
  pinMode(ouT, INPUT_PULLUP) ;  // (11) if LOW, and outbound is printed

  Serial.begin(9600); // Start serial communication at 9600 bps

// ----------------version message ------------------------
// Send version description test enclosed in a valid "V" format
// This allows the version to be read in the serial monitor, but
// also allows the network to through the message away when the 
// unit is installed in the system.
  Serial.println(this_file) ; //file name
  Serial.println(descp) ;     //description
  Serial.println(ver) ;       //version and date
  Serial.println(ver2) ;      //version and date
  Serial.println(ver3) ;      //version and date
  Serial.println() ;
// ------------ end of version message --------------------

  status = lcd.begin(LCD_COLS, LCD_ROWS);
// --------------put version on LCD ----------
  lcd.clear() ;
  lcd.home() ;
  lcd.print(this_file) ;
  lcd.setCursor(0,1) ;
  lcd.print(descp) ;
  lcd.setCursor(0,2) ;
  lcd.print(ver) ; 
  lcd.setCursor(0,3) ;
  lcd.print(ver2) ;  
  delay(5000) ;
  lcd.clear() ;
  lcd.home() ;
  
		 Wire.beginTransmission (0x68);
		//Wire.write(0x0E); //pointing Control Register
		//Wire.write(0x80);
		 busStatus = Wire.endTransmission();
	if(busStatus == 0) {
//                "01234567890123456789"
		  lcd.print("DS3231 on bus") ;
		} else {
		  lcd.setCursor(0,1) ;
		  lcd.print("DS3231 not on buss") ;
	   }
	delay(3000) ; 
	
  lcd.clear() ;
  lcd.home() ;
//  lcd.print("Buzzer Pin = ") ;
//  lcd.print(buzzer) ;
//  delay(2000) ; 
	
	tone(buzzer,400,1500) ; // (A0) test speakers
	delay(500) ;
	digitalWrite(relay, 0) ; // turn on speakers
	play() ; // go through the inbound tune once
	digitalWrite(relay, 1) ; // turn off speakers
	
  if(! busStatus) {  // read RTC status
	  RTC = Clock.read() ; // read the RTC
	  set_day = RTC.Day ;
	  set_mon = RTC.Month ;
	  set_yr = RTC.Year ; 
	  set_hr = RTC.Hour ;
	  set_min = RTC.Minute ;
	  set_sec = RTC.Second ;
	  setTime(set_hr,set_min,set_sec,set_day,set_mon,set_yr + 2000);
	  page = 1 ; // go to home page
  } else {
	  page = 2 ; // go to time set page
	  setTime(12,0,0,01,06,2022) ; // sets the flag
  }
  
  Today = day() ;

  key = 0  ;
  serialFlush() ;
//  page = 1 ; // go to home page
}
  
// ---------- End of Setup --------------
// ****************************************************************
// ------------- Loop ***********************************************
void loop() {

	if(Serial.available() > 2) {
		if(Serial.read() == 0xAA) {
			X1 = X2 ; // shift the samples down
			X2 = X3 ;
			X3 = X4 ;
			X4 = Serial.read() ; // new sample and second byte of message
			Serial.read() ;      // drop the EOF character
			digitalWrite(led,!digitalRead(led)) ; // flashes the led at 20 Hertz
			// x-value increases for inbound
			// check that the curve is monotonic
			if((X1 < X2) && (X2 < X3) && (X3 < X4) && ((X4 - X1) > 10)) Outbound = true ;
			if((X1 > X2) && (X2 > X3) && (X3 > X4) && ((X1 - X4) > 10)) Inbound = true ;
			// no time delay needed, music plays for longer than 2 seconds
	} }
	
	if(Inbound || !digitalRead(iN)) { // pin 12
	Serial.println("Inbound") ;
	   push_alarms() ; // make room at the top
	   dirs[0] = 1 ;   // "1" is "IN"
		times[0] = now() ;
		alarm_pntr = 0 ;
	//	if(!digitalRead(iN)) delay(15000) ;
	digitalWrite(relay, 0) ; // turn on speakers
	  	play() ;
	  	play() ;
	digitalWrite(relay, 1) ; // turn off speakers
		digitalWrite(buzzer, 0) ; // silence?
      delay(2000) ; // let slow vehicle pass
		serialFlush() ;
	}
	if(Outbound || !digitalRead(ouT)) { // pin 11
	Serial.println("Outbound") ;
	   push_alarms() ; // make room at the top
	   dirs[0] = 2 ;   // "2" is "OUT"
		times[0] = now() ;
		alarm_pntr = 0 ;
   //	if(!digitalRead(ouT)) delay(15000) ;
	digitalWrite(relay, 0) ; // turn on speakers
		tone(buzzer,400,1500) ;
		delay(500) ;
		tone(buzzer,200,1500) ;
		delay(500) ;
		tone(buzzer,100,1500) ;
		delay(500) ;	
	digitalWrite(relay, 1) ; // turn off speakers
		digitalWrite(buzzer, 0) ; // silence?
		serialFlush() ;
	}
	if(Inbound || Outbound) { // clear the data
		X1 = 0 ;
		X2 = 0 ;
		X3 = 0 ;
	   X4 = 0 ; 
	   Inbound = false ;
	   Outbound = false ; 
	}
		
		
	if(Today != day()) { // is it the next day?
		if(hour() == 1) { // is it 01:00?
			if(! busStatus) {
			  Today = day() ;
			  RTC = Clock.read() ; // read the RTC
			  set_day = RTC.Day ;
			  set_mon = RTC.Month ;
			  set_yr = RTC.Year ; 
			  set_hr = RTC.Hour ;
			  set_min = RTC.Minute ;
			  set_sec = RTC.Second ;
			  setTime(set_hr,set_min,set_sec,set_day,set_mon,set_yr + 2000);
			serialFlush() ;
			}
		}
	}

   get_keys() ; 
   if(key & 0x07) { // up, down, page?
		if(key & 0x03) { // UP or DOWN key
		   if(key == 1) { // up
		      alarm_pntr = alarm_pntr + 1 ;
				if(alarm_pntr > 5) alarm_pntr = 0 ;
		   } else {       // down
				alarm_pntr = alarm_pntr - 1 ;
				if(alarm_pntr > 200) alarm_pntr = 5 ; // a byte can't be negative
			}
		}
		if(key == 0x04) {         // PAGE key
			page++ ;
			if(page > 2) page = 1 ; 
		}
		key = 0 ;
	}
	
   if(page == 1) home_P() ;    // Home page
   if(page == 2) new_TOD() ;   // input clock
  }  
// ******************* End of Loop *************************************************
// *********************************************************************************

// ----------------- functions ------------------------------------

// *************************************************************************************
// ************************ Getkeys() **************************************************

// Nano 485 board w/ patch panel and crossed Rx/Tx (gen_V1)
#ifdef DU_gen1
boolean get_keys() { // 7 msec delay between samples
byte keys1 = 0 ;
byte keys2 = 0 ;
byte keys3 = 0 ;
key = 0 ;
  //must get three consecutive same key samples
  //(D8) PB_Bit0   Up
  //(D7) PD_Bit7   Down
  //(D6) PD_Bit6   Page
  //(D5) PD_Bit5   Step
  //(D2) PD_Bit2   Enter/Select
  //
  if((~PIND & 0xE4) | (~PINB & 0x01)) {       // any key down?
  keys1 = ((~PIND & 0xE4) | (~PINB & 0x01)) ; // read port_D and B0
  delay(7) ;
  keys2 = ((~PIND & 0xE4) | (~PINB & 0x01)) ; // read port_D and B0
  delay(7) ;
  keys3 = ((~PIND & 0xE4) | (~PINB & 0x01)) ; // read port_D and B0
  if(keys1 & keys2 & keys3) {
    // 3 identical samples and not empty/zero
    if(keys1 == 0x01) key = 0x01 ;  // 0x01 is UP
    if(keys1 == 0x80) key = 0x02 ;  // 0x02 is DOWN
    if(keys1 == 0x40) key = 0x04 ;  // 0x04 is PAGE
    if(keys1 == 0x20) key = 0x08 ;  // 0x08 is STEP
    if(keys1 == 0x04) key = 0x10 ;  // 0x10 is ENTER
    while ((~PIND & 0xE4) | (~PINB & 0x01)) ; // wait for key up
	 serialFlush() ; // dump 40ms of data
  } } 
  if(key != 0) {
	   T_Return = millis() ;
      return true ;
    } else {
		key = 0 ;
      return false ;
    }
  }
void key_up() {
  while((~PIND & 0xE4) | (~PINB & 0x01)) ; // wait for key up
}
#endif

// Key input pins 8-7-6-5-4
#ifdef DU_V5
	// Nano 485 board with pin header and dip jumpers (nano DU_III or DU_V)
	bool get_keys() { // 7 msec delay between samples
	byte keys1 ;
	byte keys2 ;
	byte keys3 ;

	//must get three consecutive same key samples
	  //PB_Bit0 = 8  Enter
	  //PD_Bit7 = 7  Step
	  //PD_Bit6 = 6  Page
	  //PD_Bit5 = 5  Down
	  //PD_Bit4 = 4  Up

	  // read ports D and B input pins
	  keys1 = (~PIND & 0xF0) | (~PINB & 0x01) ;
	  delay(7) ;
	  keys2 = (~PIND & 0xF0) | (~PINB & 0x01) ;
	  delay(7) ;
	  keys3 = (~PIND & 0xF0) | (~PINB & 0x01) ;
	  // 3 similar samples and not empty/zero
	  if(keys1 & keys2 & keys3) {
		 click_sound() ;
		 // translate the key data
		 if(keys1 == 0x10) key = UP ;    // 10 = up
		 if(keys1 == 0x20) key = DOWN ;  // 08 = down
		 if(keys1 == 0x40) key = PAGE ;  // 04 = page
		 if(keys1 == 0x80) key = STEP ;  // 02 = step
		 if(keys1 == 0x01) key = ENTER ; // 01 = enter
		 // wait for key up
	//	 Serial.print("Good key ") ;
	//	 Serial.println(key) ;
	//	 Serial.println("Waiting for key up") ;
		 while((~PIND & 0xF0) | (~PINB & 0x01)) ; 
	//	 Serial.println("Key is up") ;
		 T_Return = millis() ;
		 return true ;
	  } else {
		 return false ; }
	  }
#endif

//------------------- end get_keys() ----------------

// ************************************************************************

void click_sound() {
// buzzer is on digital pin #4, positive logic
  digitalWrite(buzzer, 1) ; // turn buzzer on
  delay(30) ; // wait
  digitalWrite(buzzer, 0) ; // buzzer off
}
// ------------------- end click_sound() ----------------------------

void lcd_24hr() { // ---------------------------------------
  if (hour() < 10) lcd.print("0") ;
  lcd.print(hour()) ;
  lcd.print(":") ;
  if (minute() < 10) lcd.print("0") ;
  lcd.print(minute()) ;
  lcd.print(":") ;
  if (second() < 10) lcd.print("0") ;
  lcd.print(second()) ;
  }
// ------------------ end lcd_24hr()--------------------------

void date_time() { // Prints date and time
  lcd.print(month()) ;
  lcd.print("/");
  if(day() < 10) lcd.print("0") ;
  lcd.print(day()) ;
  lcd.print("/") ;
  lcd.print(year() - 2000) ;
  lcd.print(" ") ;
  lcd_24hr() ;
  lcd.print(" ") ;
  }
//--------------------- end date_time() ----------------------------

// ------------------ home_P() (Page 1)----------------------
void home_P() {
  lcd.home() ;
  date_time() ; // Top row
  
  lcd.setCursor(18,0) ; // Top row corner
  if(X4<16) lcd.print(" ") ;
  lcd.print(X4, HEX) ;
  
  lcd.setCursor(0,1) ; // line 1
  print_line(alarm_pntr) ;
  
  lcd.setCursor(0,2) ; // line 2
  print_line(alarm_pntr + 1) ;
  
  lcd.setCursor(0,3) ; // line 3
  print_line(alarm_pntr + 2) ;

 }
// ----------------- end of home_P() (Page 1)----------------------


// -------------- set the time/RTC (page 2)----------
void new_TOD() { // reset the clock
  T_Return = millis() ; // give it 30 seconds
  lcd.clear() ;
  lcd.home() ; 
  ln_pntr = 1 ;
 
  date_time() ;
  
  lcd.setCursor(1, 1) ;
  lcd.print("YR  ") ;
  lcd.setCursor(1 ,2) ;
  lcd.print("MON ") ;  
  lcd.setCursor(1, 3) ;
  lcd.print("DAY ") ;
  lcd.setCursor(11, 1) ;
  lcd.print("HR  ") ;  
  lcd.setCursor(11, 2) ;
  lcd.print("MIN ") ; 
  
  // initialize with current system time
  set_yr  = year() - 2000 ;
  set_mon = month() ;
  set_day = day() ;
  set_hr  = hour() ;
  set_min = minute() ;
  
  do { // step through the time variables  

    lcd.setCursor(5,1) ;
      lcd_print2(set_yr) ;
    lcd.setCursor(5,2) ;
      lcd_print2(set_mon) ;
    lcd.setCursor(5,3) ;
      lcd_print2(set_day) ;
    lcd.setCursor(15,1) ;
      lcd_print2(set_hr) ;
    lcd.setCursor(15,2) ;  
      lcd_print2(set_min) ;
  
    if(ln_pntr == 1) {
      LINE = 1 ;
      CURSOR = 0 ;
      }
    if(ln_pntr == 2) {
      LINE = 2 ;
      CURSOR = 0 ;
      }
    if(ln_pntr == 3) {
      LINE = 3 ;
      CURSOR = 0 ;
      }
    if(ln_pntr == 4) {
      LINE = 1 ;
      CURSOR = 10 ;
      }
    if(ln_pntr == 5) { 
      LINE = 2 ;
      CURSOR = 10 ;
      }
    lcd.blink() ;
    lcd.setCursor(CURSOR, LINE) ;
    lcd.print(char(0x7E)) ; // arrow pointing right  
    lcd.setCursor(CURSOR, LINE) ;
      
    key = 0 ;
    while(!get_keys() && !((millis() - T_Return) > 30000)) ; // wait here
	 if((millis() - T_Return) > 30000) key = PAGE ; // exit
    if(key == STEP) {    // 0x08 = step key
      if(ln_pntr == 1) lcd.setCursor(0,1) ;
      if(ln_pntr == 2) lcd.setCursor(0,2) ;
      if(ln_pntr == 3) lcd.setCursor(0,3) ;
      if(ln_pntr == 4) lcd.setCursor(10,1) ;
      if(ln_pntr == 5) lcd.setCursor(10,2) ;
      lcd.print(" ") ;   // erase arrow
      ln_pntr = ln_pntr + 1 ;
      if(ln_pntr > 5) ln_pntr = 1 ;
      }
    if(key == UP) {  // increment the time variable
      if(ln_pntr == 1) set_yr++ ;
      if(ln_pntr == 2) set_mon++ ;
      if(ln_pntr == 3) set_day++ ;
      if(ln_pntr == 4) set_hr++ ;
      if(ln_pntr == 5) set_min++ ;
      }
    if(key == DOWN) {  // decrement the time variable
      if(ln_pntr == 1) set_yr-- ;
      if(ln_pntr == 2) set_mon-- ;
      if(ln_pntr == 3) set_day-- ;
      if(ln_pntr == 4) set_hr-- ;
      if(ln_pntr == 5) set_min-- ;
      }
      if(set_yr < 19) set_yr = 40 ; // new code required in 2040
      if(set_yr > 40) set_yr = 20 ;
      if(set_mon < 1) set_mon = 12 ;
      if(set_mon > 12) set_mon = 1 ;
      if(set_day < 1) set_day = 31 ;
      if(set_day > 31) set_day = 1 ;
      if(set_hr < 0) set_hr = 23 ;
      if(set_hr > 23) set_hr = 0 ;
      if(set_min < 0) set_min = 59 ;
      if(set_min > 59) set_min = 0 ;
      
      } while(key != ENTER && key != PAGE) ; // enter key and page key
       
  //  setTime(hr,min,sec,day,month,yr);
  if(key == ENTER) {
    RTC.Day    = set_day ;
    RTC.Month  = set_mon ;
    RTC.Year   = set_yr ; 
    RTC.Hour   = set_hr ;
    RTC.Minute = set_min ;
    RTC.Second = 0 ;
    Clock.write(RTC); // Time array in Simple Clock
    setTime(set_hr,set_min,0,set_day,set_mon,set_yr + 2000);
//	 send_Time() ;     //put time on the network
	 page = 1 ;
    }
  if(key == PAGE) page = 1 ;
  lcd.noBlink() ;
  lcd.clear() ;
  lcd.home() ;
  key = 0 ;
  serialFlush() ;
  }
// --------------- end new_TOD() (Set the RTC) (Page 2) -------------

void lcd_print2(int a) { // print a leading space if necessary
  if(a<10 && a>=0) lcd.print(" ") ;
  lcd.print(a) ;
  }
// -----------------------------------------------------------  

void lcd_print10(int a) { // print a leading zero if necessary
  if(a<10) lcd.print("0") ;
  lcd.print(a) ;
  }
// ----------------------------------------------------------- 

void lcd_print100(float a) { // print two leading spaces if necessary
  if(a<100) lcd.print(" ") ;
  if(a<10 && a>=0) lcd.print(" ") ;
  lcd.print(a, 1) ;
  }
// ----------------------------------------------------------- 

void lcd_print100i(int a) { // print two leading spaces if necessary
  if(a<100) lcd.print(" ") ;
  if(a<10) lcd.print(" ") ;
  lcd.print(a) ;
  }
// ----------------------------------------------------------- 

void serialFlush(){
  while(Serial.available() > 0) {
    char t = Serial.read();
  }
}
void printdata() {
  serialFlush() ; // start with an empty buffer
  while(Serial.available() < 40) ;
  for(i=0;i<40;i++) xss[i] = Serial.read() ;
  lcd.clear() ;
  lcd.home() ;
  for(i=0;i<40;i++) { // show all 40 bytes in hex
     if(i == 10) lcd.setCursor(0,1) ;
	  if(i == 20) lcd.setCursor(0,2) ;
	  if(i == 30) lcd.setCursor(0,3) ;
     if(xss[i] < 8) lcd.print('0') ;
	  lcd.print(xss[i],HEX) ;
	  delay(100) ;
  }
  while(!get_keys()) ; // wait here for a keystroke
  lcd.clear() ;
  lcd.home() ;
}

void push_alarms() {
	for(i=7;i>0;i--) {
		dirs[i] = dirs[i-1] ;   // move the in/out
		times[i] = times[i-1] ; // move the time of detection
	}
}

void print_line(byte Line) {
  lcd.print("   ") ;
  lcd.print(Line) ;
  lcd.print(" ") ;
  if(dirs[Line] == 1) lcd.print("IN  ") ;
  if(dirs[Line] == 2) lcd.print("OUT ") ;
  if(dirs[Line] > 0 ) {
	  if(day(times[Line]) < 10) lcd.print(" ") ;
	  lcd.print(day(times[Line])) ;
	  lcd.print("/") ;
	  if(hour(times[Line]) < 10) lcd.print("0") ;
	  lcd.print(hour(times[Line])) ;
	  lcd.print(":") ;
	  if(minute(times[Line]) < 10) lcd.print("0") ;
	  lcd.print(minute(times[Line])) ;
//	  lcd.print(":") ;
//	  if(second(times[Line]) < 10) lcd.print("0") ;
//	  lcd.print(second(times[Line])) ;
   } else {
//             "01234567890123456789"
	  lcd.print("              ") ;
	}
}

void play() {
  // iterate over the notes of the melody. 
  // Remember, the array is twice the number of notes (notes + durations)
  for (int thisNote = 0; thisNote < notes * 2; thisNote = thisNote + 2) {
    // calculates the duration of each note
    divider = melody[thisNote + 1];
    if (divider > 0) {
      // regular note, just proceed
      noteDuration = (wholenote) / divider;
    } else if (divider < 0) {
      // dotted notes are represented with negative durations!!
      noteDuration = (wholenote) / abs(divider);
      noteDuration *= 1.5; // increases the duration in half for dotted notes
    }

    // we only play the note for 90% of the duration, leaving 10% as a pause
    tone(buzzer, melody[thisNote], noteDuration*0.9);

    // Wait for the specief duration before playing the next note.
    delay(noteDuration);
    
    // stop the waveform generation before the next note.
    noTone(buzzer);
  }
}

well, durn, changed #include <TimeLib.h> to #include "TimeLib.h" and it compiles

what's the rule for using brackets versus quotes?

With the double quotes the compiler looks also in the current directory first and then in the standard places

1 Like

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