Sepnutí relé na základě času

Wiring, C++, C, Java, ...
Pravidla fóra
Toto subfórum slouží k řešení obecných otázek kolem programování (konstrukce, knihovny, alokace paměti, ...)
Odpovědět
davevo
Příspěvky: 6
Registrován: 21 zář 2017, 21:24
Reputation: 0

Sepnutí relé na základě času

Příspěvek od davevo » 21 zář 2017, 21:35

Dobrý den,
potřeboval bych poradit se zápisem podmínky IF
Mám na Arduino Uno časový modul DS3231.
Vypisuji jednotlivě hodiny,minuty,sekundy na sériovou linku i display.
Potřebuji v čas 22:30:00 sepnout relé na pinu 8.
Už jsem vyzkoušel co mě napadlo i jsem googlil ale vypisuje mě to hlášku.
macro "min" requires 2 arguments, but only 1 given
Přikládám i kod za pomoc velmi děkuji.

Kód: Vybrat vše

#include <DS3231.h>
#include <LiquidCrystal.h>

// Init the DS3231 using the hardware interface
DS3231  rtc(SDA, SCL);
LiquidCrystal lcd(12, 11, 7, 6, 5, 4);
const int relayPin =8; //rele pin 8
// Init a Time-data structure
Time  t;

void setup()
{
  // Setup Serial connection
  Serial.begin(115200);
  // Uncomment the next line if you are using an Arduino Leonardo
  //while (!Serial) {}

  // Initialize the rtc object
  rtc.begin();
  
  // The following lines can be uncommented to set the date and time
  //rtc.setDOW(WEDNESDAY);     // Set Day-of-Week to SUNDAY
  //rtc.setTime(12, 0, 0);     // Set the time to 12:00:00 (24hr format)
  //rtc.setDate(1, 1, 2014);   // Set the date to January 1st, 2014

  lcd.begin(16,2);
  pinMode(relayPin, OUTPUT); //výstup relé
}

void loop()
{
  // Get data from the DS3231
  t = rtc.getTime();
  
  // Send date over serial connection
  Serial.print("Datum ");
  Serial.print(t.date, DEC);
  Serial.print(".");
  Serial.print(t.mon, DEC);
  Serial.print(".");
  Serial.print(t.year, DEC);
  Serial.print(" ");
  
  // Send Day-of-Week and time
  Serial.print("Cas ");
  Serial.print(t.hour, DEC);
  Serial.print(":");
  Serial.print(t.min, DEC);
  Serial.print(":");
  Serial.print(t.sec, DEC);
  Serial.println(" ");

  lcd.setCursor(2,0);
  lcd.print("Cas:");
  lcd.print(t.hour, DEC);
  lcd.print(":");
  lcd.print(t.min, DEC);
  lcd.print(":");
  lcd.print(t.sec, DEC);
 
  lcd.setCursor(0,1);
  lcd.print("Datum:");
  lcd.print(t.date, DEC);
  lcd.print(".");
  lcd.print(t.mon, DEC);
  lcd.print(".");
  lcd.print(t.year, DEC);

 if (t.hour() == 21 && t.min() == 30 && t.sec() == 00) 
  {digitalWrite(relayPin, HIGH)} //Open the relay

// Wait one second before repeating :)
  delay (1000);
}

petan
Příspěvky: 358
Registrován: 23 črc 2017, 10:19
Reputation: 0
Kontaktovat uživatele:

Re: Sepnutí relé na základě času

Příspěvek od petan » 04 říj 2017, 00:21

Zkus tohle (nezkoušel jsem to):

Kód: Vybrat vše

#include <Wire.h>

//RTC DS3231
//Proměnné pro hodiny
#define DS3231_I2C_ADDRESS 0x68
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;


void setup() {
  pinMode(8, OUTPUT); 
  Wire.begin();  //komunikace I2C

}

void loop() {
	GetRtc();  //zjisti datum a čas

	if (hour==22 && minute==00){
  		digitalWrite(8, HIGH);//zapni ledku
	}

delay(1000);
}

void GetRtc() {
  Wire.beginTransmission(DS3231_I2C_ADDRESS);
  Wire.write(0); // set DS3231 register pointer to 00h
  Wire.endTransmission();
  Wire.requestFrom(DS3231_I2C_ADDRESS, 7);  // request seven bytes of data from DS3231 starting from register 00h

  second = bcdToDec(Wire.read() & 0x7f);
  minute = bcdToDec(Wire.read());
  hour = bcdToDec(Wire.read() & 0x3f);
  dayOfWeek = bcdToDec(Wire.read());
  dayOfMonth = bcdToDec(Wire.read());
  month = bcdToDec(Wire.read());
  year = bcdToDec(Wire.read());
}

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

Nevím, proč každej blne s těma hodinama tak složitě. Přitom to jde tak jednoduše, jenom s knihovnou Wire. Žádný zbytečný knihovny, nebo pointery, jen dvě funkce a pár proměnných.

seta1J
Příspěvky: 29
Registrován: 02 říj 2017, 04:32
Reputation: 0

Re: Sepnutí relé na základě času

Příspěvek od seta1J » 04 říj 2017, 11:20

if (t.hour() == 21 && t.min() == 30 && t.sec() == 00)
Nezdají se mi tam ty závorky zkus tohle.
if (t.hour == 21 && t.min == 30 && t.sec == 00)

davevo
Příspěvky: 6
Registrován: 21 zář 2017, 21:24
Reputation: 0

Re: Sepnutí relé na základě času

Příspěvek od davevo » 04 říj 2017, 15:57

JJ bylo to těma závorkama sice jsem na to přišel už dřív ale věřím že to někomu pomůže. Každopádně děkuji za radu.

Odpovědět

Kdo je online

Uživatelé prohlížející si toto fórum: Žádní registrovaní uživatelé a 2 hosti