Étape 3 :
CODE DÉFINI INTERRUPTEUR HORAIRE SELON EXIGENCE
#include « Wire.h »
#includeLiquidCrystal lcd (7, 6, 5, 4, 3, 2) ; LCD (rs, enable, d4, d5, d6, d7)
const char * AMPM ; ampoule int = 0 ;
octet seconde, minute, heure, dayOfWeek, dayOfMonth, mois, année ;
char * jours [] = {"", "soleil", "Mon", "Tue", "Wed", "Jeu", "Ven", "Sam"} ;
int H ; String s, m, d, mth, h ;
#define DS1307_I2C_ADDRESS 0x68
Byte [8] = {0b01110, 0b11111, 0b11111, 0b11111, 0b11111, 0b11111, 0b11111, 0b01010} ;
Byte [8] = {0b01110, 0b10001, 0b10001, 0b10001, 0b10001, 0b10001, 0b11111, 0b01010} ;
étincelle octet [8] = {0b00000, 0b00000, 0b00000, 0b00000, 0b00000, 0b00000, 0b10101, 0b01010} ;
void setup()
{
Wire.Begin() ;
lcd.createChar(1, on) ; SUR ampoule cracter
lcd.createChar(0, off) ; HORS AMPOULE CRATCTER
lcd.createChar (2, étincelle) ; BOUGIE AMPOULE
LCD.Begin (16, 2) ;
LCD.Print ("DIAMOND AHIR") ;
lcd.setCursor(0,1) ;
LCD.Print ("groupe X-PERT") ;
Delay(3000) ;
Serial.Begin(9600) ;
}
void loop()
{
getDateDs1307 (seconde, minute, & heure, & dayOfWeek, & dayOfMonth, & mois & année) ; OBTENIR des valeurs
AMPM() ;
Convert_Hours() ;
LCD.Clear() ; Désactivez l’affichage
DisplayTime() ; Affichage de l’heure
match_bulb_time() ; CORRESPONDANCE AVEC AMPOULE SET TIMEING
Delay(1000) ; Attendre 1 seconde
}
octet bcdToDec(byte val) {return ((val/16 * 10) + (val % 16));}
Sub getDateDs1307 (octets * second, octet * minute, byte * heure, byte * dayOfWeek, octet * dayOfMonth, octet * mois, byte * année)
{
Lire les valeurs de CCF DS1307
Wire.beginTransmission(DS1307_I2C_ADDRESS) ;
Wire.Write(0) ;
Wire.endTransmission() ;
Wire.requestFrom (DS1307_I2C_ADDRESS, 7) ;
* second = bcdToDec(Wire.read() & 0x7f) ;
* minute = bcdToDec(Wire.read()) ;
* heure = bcdToDec(Wire.read() & 0x3f) ;
* dayOfWeek = bcdToDec(Wire.read()) ;
* dayOfMonth = bcdToDec(Wire.read()) ;
* mois = bcdToDec(Wire.read()) ;
* année = bcdToDec(Wire.read()) ; }
void ampm() {(heure > 11)? () AMPM="PM"):(AMPM="AM") ; }
void Convert_Hours() {if(hour == 12|| heure == 0) H = 12 ; ElseIf (heure > 12) H = heure %12 ; d’autre H = heure ; }
Sub displaytime()
{
if(minute == 0) / / sur chaque heures MINUTES il DISPLAY FOR ONE
{
LCD.Begin (16, 2) ;
LCD.Print ("DIAMOND AHIR") ;
lcd.setCursor(0,1) ; (H < 10) ? (h = « 0 » + String(H)): (h = String(H)) ;
APPLIQUER zéro + 1to9 heures
(minute < 10) ? (m = « 0 » + String(minute)): (m = String(minute)) ; APPLIQUER zéro + avec 1to9 Minutes
((deuxième < 10) ? (s = « 0 » + String(second)): (s = String(second)) ; APPLIQUER zéro + avec 1to9 deuxième
LCD.Print ("" + String(h) + ":" + m + ":" + s + "" + AMPM) ;
}
d’autre
{
LCD.Begin (16, 2) ;
(H < 10) ? (h = « 0 » + String(H)): (h = String(H)) ; APPLIQUER zéro + 1to9 heures
(minute < 10) ? (m = « 0 » + String(minute)): (m = String(minute)) ; APPLIQUER zéro + avec 1to9 Minutes
((deuxième < 10) ? (s = « 0 » + String(second)): (s = String(second)) ; APPLIQUER zéro + avec 1to9 secondes
(dayOfMonth < 10) ? (d = « 0 » + String(dayOfMonth)): (d = String(dayOfMonth)) ; APPLIQUER zéro + avec 1to9 jour
(mois < 10) ? (mth = « 0 » + String(month)): (mth = String(month)) ; APPLIQUER zéro + 1to9 mois
lcd.setCursor(0,0) ;
LCD.Print (h + ":" + m + ":" + s + "" + AMPM) ; HEURES : MINUTES : SECONDES AM/PM
lcd.setCursor(0,1) ;
LCD.Print (d + ":" + mois + ":" + année + "" + days[dayOfWeek]) ; SEMAINE DE JOUR : MOIS : ANNÉE
}
} FUNCTION //END
Sub match_bulb_time()
{
commutateur (heure) / / appliquer l’ampoule pour sur avec heures
{/ / 6-AM à 6-PM on ampoule
case 0: ampoule = 1 ; rupture ; 12
cas 1: ampoule = 1 ; rupture ; 1
cas 2: ampoule = 1 ; rupture ; 2
case 3: ampoule = 1 ; rupture ; 3
case 4: ampoule = 1 ; rupture ; 4
cas 5: ampoule = 1 ; rupture ; 5
case 6: ampoule = 1 ; rupture ; 6
cas 7: ampoule = 0 ; rupture ; 7
cas 8: ampoule = 0 ; rupture ; 8
case 9: ampoule = 0 ; rupture ; 9
10-affaire : ampoule = 0 ; rupture ; 10
cas 11 : ampoule = 0 ; rupture ; 11
case 12 : ampoule = 0 ; rupture ; 12
case 13 : ampoule = 0 ; rupture ; 1
case 14 : ampoule = 0 ; rupture ; 2
case 15 : ampoule = 0 ; rupture ; 3
case 16 : ampoule = 0 ; rupture ; 4
cas 17 : ampoule = 0 ; rupture ; 5
Case 18 : ampoule = 1 ; rupture ; 6
case 19 : ampoule = 1 ; rupture ; 7
case 20 : ampoule = 1 ; rupture ; 8
21-affaire : ampoule = 1 ; rupture ; 9
case 22 : ampoule = 1 ; rupture ; 10
Case 23 : ampoule = 1 ; rupture ; 11
par défaut : break ;
}
if(Bulb==1) //Relay commutateur
{digitalWrite(8,LOW); / / ou se connecter à la terre
digitalWrite(9,HIGH) ; ON RELAIS
Icône d’ampoule affichage sur écran LCD
lcd.setCursor(14,0) ;
LCD.Write((Byte), 2) ;
LCD.Write((Byte), 2) ;
lcd.setCursor(14,1) ;
LCD.Write((Byte), 1) ;
LCD.Write((Byte), 1) ;
}
if(Bulb==0)
{
digitalWrite(8,LOW) ; Ou se connecter à la terre
digitalWrite(9,LOW) ; RELAIS
AMPOULE au large de l’icône d’affichage
lcd.setCursor(14,1) ;
LCD.Write((Byte), 0) ;
LCD.Write((Byte), 0) ;
}
}