Brauche Hilfe für Rtc gesteuerte Relayschaltung.
hallo ich wollte mir eine zeitschaltung mit einer rtc 3231 einem relay und einem arduino due board bauen.
die zeit und das datum werden über ein lcd display ausgegeben auch funktioniert auch der scetch kompiliert ohne fehler nur das besagte relay nicht schalten.
ich bin nicht sehr erfahren im programmieren und brauche dringend hilfe.
die zeit und das datum werden über ein lcd display ausgegeben auch funktioniert auch der scetch kompiliert ohne fehler nur das besagte relay nicht schalten.
ich bin nicht sehr erfahren im programmieren und brauche dringend hilfe.
code: [select]
#include <time.h>
#include <timelib.h>
#include <liquidcrystal_i2c.h>
#include <wire.h>
#define relay_on 0
#define relay_off 1
#define relay_1 22
liquidcrystal_i2c lcd(0x3f,20,4);
#define ds3231_i2c_address 0x68
// convert normal decimal numbers binary coded decimal
byte dectobcd(byte val)
{
return( (val/10*16) + (val%10) );
}
// convert binary coded decimal normal decimal numbers
byte bcdtodec(byte val)
{
return( (val/16*10) + (val%16) );
}
void setup() {
wire.begin();
lcd.init(); // initialize lcd
lcd.backlight();
lcd.home();
pinmode(relay_1, output); // relay 1
}
void readds3231time(byte *second,
byte *minute,
byte *hour,
byte *dayofweek,
byte *dayofmonth,
byte *month,
byte *year)
{
wire.begintransmission(ds3231_i2c_address);
wire.write(0); // set ds3231 register pointer 00h
wire.endtransmission();
wire.requestfrom(ds3231_i2c_address, 7);
// request 7 bytes of data ds3231 starting 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());
}
void loop() {
byte second, minute, hour, dayofweek, dayofmonth, month, year;
// retrieve data ds3231
readds3231time(&second, &minute, &hour, &dayofweek, &dayofmonth, &month,
&year);
lcd.setcursor(0, 3);
if(hour < 10){ // wenn kleiner 10 schreibe eine 0 davor
lcd.print("0");}
lcd.print(hour);
lcd.setcursor(2, 3);
lcd.print(":");
lcd.setcursor(3, 3);
if(minute < 10){ // wenn kleiner 10 schreibe eine 0 davor
lcd.print("0");}
lcd.print(minute);
lcd.setcursor(5, 3);
lcd.print(":");
lcd.setcursor(6, 3);
if(second < 10){ // wenn kleiner 10 schreibe eine 0 davor
lcd.print("0");}
lcd.print(second);
lcd.setcursor(8, 3);
lcd.print("uhr");
lcd.setcursor(12, 3);
if(dayofmonth < 10){ // wenn kleiner 10 schreibe eine 0 davor
lcd.print("0");}
lcd.print(dayofmonth);
lcd.setcursor(14, 3);
lcd.print("/");
lcd.setcursor(15, 3);
if(month < 10){ // wenn kleiner 10 schreibe eine 0 davor
lcd.print("0");}
lcd.print(month);
lcd.setcursor(17, 3);
lcd.print("/");
lcd.setcursor(18, 3);
lcd.print(year);
relais1();
}
void relais1() {
if( second() == 30)
{
digitalwrite(relay_1, relay_on);
}
if( second() == 0)
{
digitalwrite(relay_1, relay_off );
}
}
Arduino Forum > International > Deutsch (Moderator: uwefed) > Brauche Hilfe für Rtc gesteuerte Relayschaltung.
arduino
Comments
Post a Comment