loading

I need arduino code help.

I want to do arduino time relay with RTC and LCD, but i have problems with the code.
This is my code:


#include "Wire.h"
#define DS1307_ADDRESS 0x68
#include <LiquidCrystal.h>
byte zero = 0x00;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int rele=7;

#define DS1307_I2C_ADDRESS 0x68 
#define STA_HOUR 16
#define STA_MINUTE 15
#define STA_SECOND 0

#define END_HOUR 16
#define END_MINUTE 17
#define END_SECOND 0



void setup(){
  Wire.begin();
  Serial.begin(9600);
  setDateTime();
lcd.begin(16, 2);
pinMode(rele,OUTPUT);

}

void loop(){
  printDate();
  delay(1000);
  lcd.begin(16, 2);
}

void setDateTime(){

  byte second =      0; //0-59
  byte minute =      13; //0-59
  byte hour =        16; //0-23
  byte weekDay =     2; //1-7
  byte monthDay =    2; //1-31
  byte month =       8; //1-12
  byte year  =       13; //0-99

  Wire.beginTransmission(DS1307_ADDRESS);
  Wire.write(zero);

  Wire.write(decToBcd(second));
  Wire.write(decToBcd(minute));
  Wire.write(decToBcd(hour));
  Wire.write(decToBcd(weekDay));
  Wire.write(decToBcd(monthDay));
  Wire.write(decToBcd(month));
  Wire.write(decToBcd(year));

  Wire.write(zero);

  Wire.endTransmission();

}

byte decToBcd(byte val){

  return ( (val/10*16) + (val%10) );
}

byte bcdToDec(byte val)  {

  return ( (val/16*10) + (val%16) );
}

void printDate(){

 
  Wire.beginTransmission(DS1307_ADDRESS);
  Wire.write(zero);
  Wire.endTransmission();

  Wire.requestFrom(DS1307_ADDRESS, 7);

  int second = bcdToDec(Wire.read());
  int minute = bcdToDec(Wire.read());
  int hour = bcdToDec(Wire.read() & 0b111111);
  int weekDay = bcdToDec(Wire.read());
  int monthDay = bcdToDec(Wire.read());
  int month = bcdToDec(Wire.read());
  int year = bcdToDec(Wire.read());


 
  lcd.print(monthDay);
  lcd.print("/");
  lcd.print(month);
  lcd.print("/");
  lcd.print(year);
  lcd.print(" ");
  lcd.print(hour);
  lcd.print(":");
  lcd.print(minute);
  lcd.print(":");
  lcd.println(second);}

if (minute = STA_MINUTE && hour = STA_HOUR)
{
digitalWrite(rele,HIGH);
}
if (minute = END_MINUTE && hour = END_HOUR)
{
digitalWrite(rele,LOW);
}

The errors :
chasovnik_lcd:104: error: expected unqualified-id before 'if'
chasovnik_lcd:108: error: expected unqualified-id before 'if'

dalucero3 years ago
I think you're errors are because there is a closing curly brace on the line preceding the if statements. The if statements don't appear to be inside a function.
inaydenov1 (author) 3 years ago
I want to have clock with date on the lcd and at a specific time to activate the relay. With this code(without if statement), i have only clock and date. I can`t activate relay.
#include "Wire.h"
#define DS1307_ADDRESS 0x68
byte zero = 0x00; //workaround for issue #527


void setup(){
Wire.begin();
Serial.begin(9600);
setDateTime(); //MUST CONFIGURE IN FUNCTION
}

void loop(){
printDate();
delay(1000);
}

void setDateTime(){

byte second = 45; //0-59
byte minute = 40; //0-59
byte hour = 0; //0-23
byte weekDay = 2; //1-7
byte monthDay = 1; //1-31
byte month = 3; //1-12
byte year = 11; //0-99

Wire.beginTransmission(DS1307_ADDRESS);
Wire.write(zero); //stop Oscillator

Wire.write(decToBcd(second));
Wire.write(decToBcd(minute));
Wire.write(decToBcd(hour));
Wire.write(decToBcd(weekDay));
Wire.write(decToBcd(monthDay));
Wire.write(decToBcd(month));
Wire.write(decToBcd(year));

Wire.write(zero); //start

Wire.endTransmission();

}

byte decToBcd(byte val){
// Convert normal decimal numbers to binary coded decimal
return ( (val/10*16) + (val%10) );
}

byte bcdToDec(byte val) {
// Convert binary coded decimal to normal decimal numbers
return ( (val/16*10) + (val%16) );
}

void printDate(){

// Reset the register pointer
Wire.beginTransmission(DS1307_ADDRESS);
Wire.write(zero);
Wire.endTransmission();

Wire.requestFrom(DS1307_ADDRESS, 7);

int second = bcdToDec(Wire.read());
int minute = bcdToDec(Wire.read());
int hour = bcdToDec(Wire.read() & 0b111111); //24 hour time
int weekDay = bcdToDec(Wire.read()); //0-6 -> sunday - Saturday
int monthDay = bcdToDec(Wire.read());
int month = bcdToDec(Wire.read());
int year = bcdToDec(Wire.read());

//print the date EG 3/1/11 23:59:59
Serial.print(month);
Serial.print("/");
Serial.print(monthDay);
Serial.print("/");
Serial.print(year);
Serial.print(" ");
Serial.print(hour);
Serial.print(":");
Serial.print(minute);
Serial.print(":");
Serial.println(second);}
Why did you remove the if statements? all you had to do was add the ';' where they where needed.
What problems are you having with the code? What results are you expecting and what are you getting.

BTW the errors your getting are telling you that your missing the semi colons at the end of the If statements.