// Date and time functions using a DS3231 RTC connected via I2C and Wire lib
#include <Wire.h>
#include "RTClib.h"
#include "LiquidCrystal_I2C.h"
RTC_DS3231 rtc;
LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 for a 16 chars and 2 line display
int motor[] ={26,28,30,32};
int matin = 13; //bouton ration 1
int midi = 12; //bouton ration 2
int soir = 11; // bouton ration 3
int matin_bis = 10; // bouton ration 4
int midi_bis = 9; // bouton ration 5
int soir_bis = 8; // bouton ration 6
int led_green =42; //Green led
int led_red=44; //Red led
int led_yellow=46; //Yellow led
//set the variable for alarm elements
int alarm_hour = 0;
int alarm_minute = 0;
int alarm_second =0;
int alarm_base = 120;
int alarm_new;
//set the variable for counter elements
int counter = 5;
int i;
int motor_counter;
int page_counter=1 ; //To move beetwen pages
int subpage_counter=0; // To subpage in select portion
int subpage2_counter=0; // To subpage in next time for portion
int portion_counter = 00; //To select portion options
//---------Storage debounce function-----//
boolean current_up = LOW;
boolean last_up=LOW;
boolean last_sel= LOW;
boolean current_sel = LOW;
//Custom return char
byte back[8] = {
0b00100,
0b01000,
0b11111,
0b01001,
0b00101,
0b00001,
0b00001,
0b11111
};
//Custom arrow char
byte arrow[8] = {
0b01000,
0b00100,
0b00010,
0b11111,
0b00010,
0b00100,
0b01000,
0b00000
};
//----------------------------------------------------------------------------
void currentTime(){
DateTime now = rtc.now();
lcd.setCursor(0,0);
lcd.print("Time:");
lcd.setCursor(6,0);
if (now.hour() <10){ lcd.print("0");}
lcd.print(now.hour(), DEC );
lcd.print(':');
if (now.minute() <10){ lcd.print("0");}
lcd.print(now.minute(), DEC );
lcd.print(':');
if (now.second() <10){lcd.print("0");}
lcd.print(now.second(), DEC);
}
//----------------------------------------------------------------------------
void setup () {
lcd.init();
lcd.backlight(); // initialize the lcd
pinMode(motor[0], OUTPUT);
pinMode(motor[1], OUTPUT);
pinMode(motor[2], OUTPUT);
pinMode(motor[3], OUTPUT);
pinMode(led_green, OUTPUT);
pinMode(led_red, OUTPUT);
pinMode(led_yellow, OUTPUT);
digitalWrite(motor[0], LOW);
digitalWrite(motor[1], LOW);
digitalWrite(motor[2], LOW);
digitalWrite(motor[3], LOW);
digitalWrite(led_green, LOW);
digitalWrite(led_red, LOW);
digitalWrite(led_yellow, LOW);
delay(3000); // wait for console opening
if (! rtc.begin()) {
lcd.println("Pas de RTC");
while (1);
}
if (rtc.lostPower())
{
lcd.println("alim RTC perdue");
// following line sets the RTC to the date & time this sketch was compiled
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
// This line sets the RTC with an explicit date & time, for example to set
// January 21, 2014 at 3am you would call:
// rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
}
lcd.createChar(1, back);
lcd.createChar(2, arrow);
}
//---- De-bouncing function for all buttons----//
boolean debounce(boolean last, int pin)
{
boolean current = digitalRead(pin);
if (last != current)
{
delay(5);
current = digitalRead(pin);
}
return current;
}
//--------------------------------------------------------------------------------------------
void loop () {
}