je t'ai mis le code complet avec la course du soleil et le turntable .
encoder sert : appui court de passer d'un ecran à l'autre (premier ecran course du soleil , deuxieme ecran turntable )
appui long reglage rtc .
#include <Wire.h>
#include "RTClib.h"
#include <Encoder.h> // from http://www.pjrc.com/teensy/td_libs_Encoder.html
Encoder knob(2, 3); //encoder connected to pins 2 and 3 (and ground)// D2 SEEDSTUDIO shield //3,4
#include <TimeLib.h>
#include <TimeLord.h>
#include <EEPROM.h>
#include <Stepper.h>
const float LATITUDE = 43.70, LONGITUDE = 7.25; // Nice Sun
const int TIMEZONE = + 1;
int r = 35;//cercle drawLine
int r_1 = 35;//drawbitmap
int angle = 0;
int x1=57;// drawbitmap rattrapage width 65-8 = 57
int y1=42;// drawbitmap rattrapage height 50-8 = 42
int x0=65;// drawLine
int y0=50;// drawLine
int sun;
//int alfa = 0;
int alfa_1 = 0;
int degre = 0;
//int backlight = 6; //backlight control pin 6
const int nbrepas360 = 48; // Fixe le nombre de pas pour faire un tour complet, c'est-à-dire 360°.
Stepper monmoteur (nbrepas360, 8, 9, 10, 11); // Initialise la librairie Stepper.h
int cptepas = 0; // Stockera le nombre de pas compté.
float position_du_moteur=0;
int degrees_pas = 0.5;
#define u8g_logo_width 16
#define u8g_logo_height 16
#if defined(ARDUINO_ARCH_SAMD)
// for Zero, output on USB Serial console, remove line below if using programming port to program the Zero!
#define Serial SerialUSB
#endif
RTC_DS1307 RTC;
char daysOfTheWeek[7][12] = {"Dim", "Lun", "Mar", "Mer", "Jeu", "Ven", "Sam"};
#include "U8glib.h"
U8GLIB_SH1106_128X64 u8g(U8G_I2C_OPT_NONE);
//U8GLIB_SSD1309_128X64 u8g(U8G_I2C_OPT_NONE);
//U8GLIB_ST7920_128X64 u8g(13, 11, 12, U8G_PIN_NONE);//U8GLIB_ST7920_128X64_1X u8g(7, 6, 5 ,8); //Enable, RW, RS, RESET
/*
const uint8_t bonsai_bitmap[] PROGMEM = {
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // ................................................................................................................................
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // ................................................................................................................................
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // ................................................................................................................................
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0x80,0x00,0x00,0x00,0x00,0x00,0x00, // .................................................................########.......................................................
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0xFF,0xF3,0xF0,0x00,0x00,0x00,0x00,0x00, // ............................................................################..######............................................
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFE,0x00,0x00,0x00,0x00,0x00, // ........................................................###############################.........................................
0x00,0x00,0x00,0x00,0x00,0x0F,0xFF,0xFF,0xFF,0xFE,0x7F,0x00,0x00,0x00,0x00,0x00, // ............................................###################################..#######........................................
0x00,0x00,0x00,0x00,0x00,0x1F,0xFF,0xFF,0xFF,0xF8,0x1F,0x00,0x00,0x00,0x00,0x00, // ...........................................##################################......#####........................................
0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0x80,0x00,0x7F,0x00,0x00,0x00, // ................................................#################################................#######........................
0x00,0x00,0x00,0x00,0x00,0x3F,0xFF,0xFF,0xFF,0xFF,0xF8,0x01,0xFF,0x83,0xE0,0x00, // ..........................................###########################################..........##########.....#####.............
0x00,0x00,0x00,0x00,0x00,0x3F,0xFF,0xFF,0xFF,0xFF,0xFC,0x19,0xFC,0xFF,0xF0,0x00, // ..........................................############################################.....##..#######..############............
0x00,0x00,0x00,0x00,0x00,0x07,0xFF,0xFF,0xFD,0xFF,0x30,0x3F,0xFF,0xFF,0xE0,0x00, // .............................................#########################.#########..##......#########################.............
0x00,0x00,0x00,0x00,0x00,0x1F,0xFF,0xFF,0xF8,0x00,0x07,0xFF,0xFF,0xFC,0x00,0x00, // ...........................................##########################................#########################..................
0x00,0x00,0x00,0x00,0x00,0x3F,0xFF,0xFF,0xE0,0x00,0x7F,0xFF,0xFF,0xFC,0xF8,0x00, // ..........................................#########################..............#############################..#####...........
0x00,0x00,0x00,0x00,0x1C,0x1F,0xFF,0x8F,0x80,0x3F,0xFF,0xFF,0xFF,0xFF,0xF8,0x00, // ...................................###.....##############...#####.........###########################################...........
0x00,0x00,0x00,0x00,0x3F,0xFF,0xFF,0x87,0xFF,0xFF,0xFF,0xFF,0x80,0x7F,0xE0,0x00, // ..................................#######################....####################################........##########.............
0x00,0x00,0x00,0x00,0x3F,0xFF,0xFF,0x87,0xFF,0xC0,0x03,0xC3,0xE0,0x00,0x00,0x00, // ..................................#######################....#############............####....#####.............................
0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0x0F,0xF0,0x00,0x00,0x01,0xE0,0x00,0x00,0x00, // ........................................################....########...........................####.............................
0x00,0x00,0x00,0x00,0x01,0xFF,0x87,0xFF,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // .......................................##########....############...............................................................
0x00,0x00,0x00,0x00,0x00,0x0F,0xF0,0xFF,0x00,0x00,0x00,0x03,0xFC,0x00,0x00,0x00, // ............................................########....########..............................########..........................
0x00,0x00,0x3F,0xE7,0xDF,0x01,0xF0,0x3F,0xC0,0x00,0x7F,0x07,0xC0,0x07,0xF0,0x00, // ..................#########..#####.#####.......#####......########...............#######.....#####...........#######............
0x00,0x00,0x1F,0xFF,0xFF,0xF8,0x00,0x1F,0xF8,0x00,0xFF,0xFF,0xFF,0xFF,0xF0,0x00, // ...................##########################..............##########...........####################################............
0x00,0x00,0x01,0xFF,0xFF,0xFF,0xFF,0xBF,0xFF,0xE0,0x3F,0xFF,0xFF,0xFF,0xF8,0x00, // .......................##################################.#################.......###################################...........
0x00,0x00,0x1F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xE1,0xFF,0xFF,0xFF,0xFF,0xFF,0x00, // ...................########################################################....#########################################........
0x00,0xDF,0xBF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x80, // ........##.######.#######################################################################################################.......
0x01,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x80, // .......##################################################################################################################.......
0x03,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFE,0x00,0x7F,0xFF,0xFF,0xFF,0xE0,0x00, // ......#################################################################..........##################################.............
0x01,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xF0,0x00,0x3F,0xFF,0xFF,0xFF,0xFF,0x00, // .......#############################################################..............######################################........
0x00,0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x1F,0xFF,0xFF,0xFF,0x0E,0x00, // .........#######################################################...................#############################....###.........
0x00,0x1F,0xFF,0xFF,0xFF,0xFF,0x87,0xFC,0x03,0xF0,0x00,0x1F,0x0F,0xFC,0x00,0x00, // ...........######################################....#########........######...............#####....##########..................
0x00,0x3F,0xFF,0xFF,0xC7,0xFF,0x1F,0xF0,0xE3,0xF9,0xE0,0x0E,0x0F,0xFF,0x80,0x00, // ..........########################...###########...#########....###...#######..####.........###.....#############...............
0x00,0xFF,0xFF,0xF3,0x80,0x00,0x1F,0xC1,0xFF,0xFF,0xF0,0x00,0x00,0x00,0x00,0x00, // ........####################..###..................#######.....#####################............................................
0x00,0x7E,0x1F,0xE7,0x80,0x00,0x7F,0xFF,0xFF,0xFF,0xFF,0x80,0x00,0x00,0x00,0x00, // .........######....########..####................########################################.......................................
0x00,0x3E,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xC0,0x00,0x00,0x00,0x00, // ..........#####.................................##########################################......................................
0x00,0x00,0x00,0x00,0x00,0x03,0xFF,0x0C,0x7C,0x3F,0x03,0xC0,0x00,0x00,0x00,0x00, // ..............................................##########....##...#####....######......####......................................
0x00,0x00,0x00,0x00,0x00,0x07,0xFC,0x00,0x00,0x07,0xF8,0x00,0x00,0x00,0x00,0x00, // .............................................#########.......................########...........................................
0x00,0x00,0x00,0x00,0x00,0x07,0xFC,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // .............................................#########..........................................................................
0x00,0x00,0x00,0x00,0x00,0x0F,0xFC,0x00,0x00,0x01,0x00,0x00,0x01,0x40,0x00,0x00, // ............................................##########.........................#.......................#.#......................
0x00,0x00,0x00,0x00,0x00,0x0F,0xFF,0xC0,0x00,0x01,0x00,0x00,0x00,0x00,0xE0,0x00, // ............................................##############.....................#................................###.............
0x00,0x00,0x00,0x00,0x00,0x07,0xFF,0xFC,0x00,0x01,0xC6,0x31,0xCC,0x81,0x10,0x00, // .............................................#################.................###...##...##...###..##..#......#...#............
0x00,0x00,0x00,0x00,0x00,0x03,0xFF,0xFF,0x80,0x01,0x29,0x4A,0x12,0x81,0x10,0x00, // ..............................................###################..............#..#.#..#.#..#.#....#..#.#......#...#............
0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0xFF,0xC0,0x01,0x29,0x49,0x9E,0x81,0x10,0x00, // ....................................................##############.............#..#.#..#.#..#..##..####.#......#...#............
0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xFF,0xE0,0x01,0x29,0x48,0x52,0x80,0xA0,0x00, // ......................................................#############............#..#.#..#.#..#....#.#..#.#.......#.#.............
0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xFF,0xF0,0x00,0xC6,0x4B,0x92,0x91,0xB0,0x00, // .....................................................###############............##...##..#..#.###..#..#.#..#...##.##............
0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // ................................................#####################...........................................................
0x00,0x00,0x00,0x1F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x80,0x00,0x00,0x00,0x00, // ...........................##############################################################.......................................
0x00,0x00,0x0F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00, // ....................############################################################################................................
0x00,0x00,0x7F,0xE0,0x00,0x1F,0xFF,0xE0,0x00,0x00,0x00,0x3F,0xF0,0x00,0x00,0x00, // .................##########................################...............................##########............................
0x00,0x00,0x78,0x03,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00, // .................####.........#####.............................................................####............................
0x00,0x00,0x7F,0x73,0xFC,0x00,0x00,0x00,0x00,0x00,0x00,0xF8,0x70,0x00,0x00,0x00, // .................#######.###..########..................................................#####....###............................
0x00,0x00,0x3F,0xFF,0xC0,0x00,0x00,0x00,0x00,0x00,0x07,0xFF,0xF0,0x00,0x00,0x00, // ..................################...................................................###############............................
0x00,0x00,0x1F,0xFF,0xE0,0x00,0x00,0x00,0x00,0x00,0x1F,0xFF,0xE0,0x00,0x00,0x00, // ...................################................................................################.............................
0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x80,0x00,0x00,0x00, // ........................#########################################################################...............................
0x00,0x00,0x00,0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFE,0x00,0x00,0x00,0x00, // .........................######################################################################.................................
0x00,0x00,0x00,0x1F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xF8,0x00,0x00,0x00,0x00, // ...........................##################################################################...................................
0x00,0x00,0x00,0x07,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xC0,0x00,0x00,0x00,0x00, // .............................#############################################################......................................
0x00,0x00,0x00,0x01,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00, // ...............................#########################################################........................................
0x00,0x00,0x00,0x01,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFE,0x00,0x00,0x00,0x00,0x00, // ...............................########################################################.........................................
0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xF8,0x00,0x00,0x00,0x00,0x00, // ................................#####################################################...........................................
0x00,0x00,0x00,0x00,0x0F,0xFF,0xFF,0xFF,0xFF,0xFF,0xF0,0x00,0x00,0x00,0x00,0x00, // ....................................################################################............................................
0x00,0x00,0x00,0x00,0x0F,0xC0,0x00,0xFF,0xC0,0x07,0xE0,0x00,0x00,0x00,0x00,0x00, // ....................................######..............##########...........######.............................................
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // ................................................................................................................................
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // ................................................................................................................................
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 // ................................................................................................................................
};
0x00, 0x00, 0x80, 0x00, 0x80, 0x01, 0x84, 0x10, 0x08, 0x08, 0xe0, 0x03, 0x10, 0x04, 0x10, 0x04, 0x17, 0x74, 0x10, 0x04, 0x10, 0x04, 0xe0, 0x03, 0x08, 0x08, 0x84, 0x10, 0x80, 0x01, 0x00, 0x00
*/
static unsigned char u8g_sun_3_bits[] U8G_PROGMEM = {// soleil
0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x80, 0x00, 0x90, 0x04, 0xa0, 0x02, 0xc0, 0x01, 0xfc, 0x1f, 0xc0, 0x01, 0xa0, 0x02, 0x90, 0x04, 0x80, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
/*
int X = 0;
int Y = 0;
int I = 0;
int X2 = 0;
int Y2 = 0;
int X3 = 0;
int Y3 = 0;
*/
int Timer = 0;
int Minutt = 0;
int Sekund = 0;
float Vinkel = 0;
int an = 0;
int luna = 0;
int zi = 0;
int zis = 0;
/*
int ScreenWith = 128;
int ScreenWithC = 64;
int ScreenHeight = 64;
int ScreenHeightC = 32;
int yArray[128];
int deics = ScreenWith/4;
int deigrec = 14;
int deics2 = 0;
int de = 10;
*/
//the variables provide the holding values for the set clock routine
int setyeartemp;
int setmonthtemp;
int setdaytemp;
int setoretemp;
int setzitemp;
int setminstemp;
int setsecs = 0;
int maxday; // maximum number of days in the given month
int TimeMins; // number of seconds since midnight
int TimerMode = 2; //mode 0=Off 1=On 2=Auto
int TimeOut = 10;
int TimeOutCounter;
// These variables are for the push button routine
int buttonstate = 0; //flag to see if the button has been pressed, used internal on the subroutine only
int pushlengthset = 1500; // value for a long push in mS
int pushlength = pushlengthset; // set default pushlength
int pushstart = 0;// sets default push value for the button going low
int pushstop = 0;// sets the default value for when the button goes back high
int pwm2 ;// pwm Sun
int margeAube,margeCrepuscule;
int heureMidi;
int Sunrise, Sunset,Sun_zenith ; //sunrise and sunset expressed as minute of day (0-1439)
TimeLord myLord; // TimeLord Object, Global variable
byte sunTime[] = {0, 0, 0, 1, 1, 13}; // 17 Oct 2013
int SunriseHour, SunriseMin, SunsetHour, SunsetMin,zenithHour,zenithMin,zenith,zenith_Hour,zenith_Min ;
int knobval; // value for the rotation of the knob
boolean buttonflag = false; // default value for the button flag
//#define buton 4
//char s[3] = "";
int backlight = 6;//backlight control pin 6
#include <stdlib.h>
char tmp_string[8];
void draw(void) {
DateTime now = RTC.now();
//Timelord initialisation
myLord.TimeZone(TIMEZONE * 60);
myLord.Position(LATITUDE, LONGITUDE);
sunTime[3] = now.day(); // Give Timelord the current date
sunTime[4] = now.month();
sunTime[5] = now.year();
myLord.SunRise(sunTime); // Computes Sun Rise.
Sunrise = sunTime[2] * 60 + sunTime[1]; // Sunrise returned in minutes past midnight
SunriseHour = sunTime[2];
SunriseMin = sunTime [1];
sunTime[3] = now.day(); // Uses the Time library to give Timelord the current date
sunTime[4] = now.month();
sunTime[5] = now.year();
myLord.SunSet(sunTime); // Computes Sun Set.
Sunset = sunTime[2] * 60 + sunTime[1]; // Sunset returned in minutes past midnight
SunsetHour = sunTime[2];
SunsetMin = sunTime [1];
EEPROM.update(14,zenith_Hour);
EEPROM.update(15,zenith_Min);
zenithMin = (Sunset+Sunrise)/2;
zenith_Min = (zenithMin)%60;
zenithHour = (Sunset+Sunrise)/2;
zenith_Hour = (zenithHour)/60;
TimeMins = (now.hour() * 60) + now.minute();
uint16_t time = now.hour() * 60 + now.minute();
uint16_t angle = map(time, Sunrise, Sunset, 0, 180);// Angle
/*evite de depasser l'angle*/
if(angle < 0)
angle = 0;
else if(angle > 180)
angle = 180;
margeAube = (Sunset - Sunrise)/180*6; //calcul de la durer de uint16_t angle multiplier par 6° angle Aube Civil
heureMidi = (Sunrise + Sunset)/2;
margeCrepuscule =(Sunset - Sunrise)/180*6; //calcul de la durer de uint16_t angle multiplier par 6° angle Crepuscule Civil
if(TimeMins < heureMidi ){
pwm2 = map ( time, Sunrise - margeAube, heureMidi, 0, 255);
}
else {
pwm2 = map ( time, heureMidi, Sunset + margeCrepuscule, 255, 0);
}
if(pwm2<0) {
pwm2=0;
}
analogWrite(5,pwm2);// PIN 5 timer 8 bits
int maxday;// maximum de jours
if (now.month() == 4 || now.month() == 5 || now.month() == 9 || now.month() == 11){ //30 jours = Septembre, Avril, Juin, Novembre.
maxday = 30;
EEPROM.update(7,maxday);
}
else {
maxday = 31; //... all the others have 31
EEPROM.update(7,maxday);
}
if (now.month() == 2 && now.year() % 4 == 0){ //... Exception Fevrier = 28 jours , ou 29 jours année bissextile.
maxday = 29;
EEPROM.update(7,maxday);
}
if (now.month() == 2 && now.year() % 4 != 0){
maxday = 28;
EEPROM.update(7,maxday);
}
EEPROM.update(9,SunriseHour);
EEPROM.update(10,SunriseMin);
EEPROM.update(11,SunsetHour);
EEPROM.update(12,SunsetMin);
EEPROM.update(13,angle);
u8g.setFont(u8g_font_6x13);
u8g.setPrintPos(2,10);
if (zi < 10) u8g.print("0");
u8g.print(zi);
u8g.print("/");
if (luna < 10) u8g.print("0");
u8g.print(luna);
u8g.print("/");
u8g.setPrintPos(40,10);
u8g.print(daysOfTheWeek[zis]);
u8g.setFont(u8g_font_6x13);
u8g.setPrintPos(80,10);
if (Timer < 10) u8g.print(" ");
u8g.print(Timer);
u8g.setPrintPos(93,10);
if (Sekund%2 != 1)
u8g.print(":");
u8g.setPrintPos(115,10);
u8g.setFont(u8g_font_6x10);
if(Sekund<10)u8g.print("0");
u8g.print(Sekund);
u8g.setPrintPos(100,10);
u8g.setFont(u8g_font_6x13);
if (Minutt < 10) u8g.print("0");
u8g.print(Minutt);
// Display sun moon //
/*
u8g.setPrintPos(8,20);
u8g.setFont(u8g_font_6x10);
u8g.print("Sun");
u8g.setPrintPos(27,20);
u8g.print("R");
u8g.setPrintPos(34,20);
if(SunriseHour<10);
u8g.print("0");
u8g.print(SunriseHour);
u8g.print (":");
if (SunriseMin <10)
u8g.print("0");
u8g.print (SunriseMin);
u8g.setPrintPos(85,20);
u8g.print ("S");
u8g.setPrintPos(93,20);
if(SunsetHour<10)
u8g.print("0");
u8g.print (SunsetHour);
u8g.print (":");
if (SunsetMin <10)
u8g.print("0");
u8g.print (SunsetMin);
*/
/* affichage heure zenith*/
u8g.setFont(u8g_font_6x10);
u8g.setPrintPos(95,20 );
if(EEPROM.read(14)<0)
u8g.print("0");
u8g.print(EEPROM.read(14));
u8g.print(":");
if (EEPROM.read(15) <10)
u8g.print("0");
u8g.print (EEPROM.read(15));
/* affichage maxday */
u8g.setFont(u8g_font_6x10);
u8g.setPrintPos(105,30 );
u8g.print(EEPROM.read(7));
/* affichage margeAube*/
u8g.setFont(u8g_font_6x10);
u8g.setPrintPos(1,30 );
u8g.print(margeAube);
/* affichage pwm2*/
u8g.setFont(u8g_font_6x10);
u8g.setPrintPos(1,20 );
u8g.print(pwm2);
/* affichege heureMidi*/
u8g.setFont(u8g_font_6x10);
u8g.setPrintPos(1,40 );
u8g.print(heureMidi);
/* affichage angle */
u8g.setFont(u8g_font_6x10);
u8g.setPrintPos(54,60 );
u8g.print(angle);
EEPROM.update(13,angle);
u8g.setFont(u8g_font_6x10);
u8g.setPrintPos(5,60);
if(EEPROM.read(9)<10);
u8g.print("0");
u8g.print(EEPROM.read(9));
u8g.print (":");
if (EEPROM.read(10) <10)
u8g.print("0");
u8g.print (EEPROM.read(10));
u8g.setPrintPos(95,60);
if(EEPROM.read(11)<10)
u8g.print("0");
u8g.print (EEPROM.read(11));
u8g.print (":");
if (EEPROM.read(12) <10)
u8g.print("0");
u8g.print (EEPROM.read(12));
maxday = EEPROM.read(7);
alfa_1=360*now.day()/maxday;
EEPROM.update(16,alfa_1);
u8g.drawLine(20, 50, 110, 50);//droite du bas de l'écran
u8g.drawCircle(x0, y0, r, U8G_DRAW_UPPER_RIGHT);//x0=65,y0=50,r=35
u8g.drawCircle(x0, y0, r, U8G_DRAW_UPPER_LEFT);//cercle
//u8g.drawLine(x0,y0,x0-r*cos(1*angle*2*3.14/360),y0-r*sin(1*angle*2*3.14/360));//droite qui visualise l'angle du soleil
u8g.drawXBMP(x1-r_1*cos(1*angle*2*3.14/360),y1-r_1*sin(1*angle*2*3.14/360),u8g_logo_width, u8g_logo_height, u8g_sun_3_bits);//dessin du soleil
//x1=57,y1=43,r_1=35,u8g_logo_width = 16,u8g_logo_height = 16,
TimeMins = (now.hour() * 60) + now.minute();
if (TimeMins >= Sunrise && TimeMins <=Sunset-1) { //If it's after sunrise and before sunset, switch our relay on
digitalWrite (A3, HIGH);// cdt PONT H
//analogWrite(backlight,255);// lcd rétroéclairage On
u8g.setColorIndex(1); // Pixel On
}
else { //otherwise switch it off
digitalWrite (A3,LOW);// cdt PONT H
//analogWrite(backlight,0);// lcd rétroéclairage Off
u8g.setColorIndex(0);// Pixel Off
}
}
void setup(void) {
u8g.setContrast(0);//Config the constrast to the best effect
//u8g.setRot();
analogWrite(backlight,255);
// assign default color value
if ( u8g.getMode() == U8G_MODE_R3G3B2 )
u8g.setColorIndex(255); // white
else if ( u8g.getMode() == U8G_MODE_GRAY2BIT )
u8g.setColorIndex(3); // max intensity
else if ( u8g.getMode() == U8G_MODE_BW )
u8g.setColorIndex(1); // pixel on
u8g.setFont(u8g_font_6x10);
#ifndef ESP8266
while (!Serial); // for Leonardo/Micro/Zero
#endif
Serial.begin(9600);
if (! RTC.begin()) {
Serial.println("Couldn't find RTC");
while (1);
}
if (! RTC.isrunning()) {
Serial.println("RTC is NOT running!");
RTC.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
pinMode(A0,INPUT);//push button on encoder connected to A0 (and GND)
digitalWrite(A0,HIGH); //Pull button high
pinMode (5,OUTPUT); // pwm led horticole
analogWrite(5,0);//pwm led horticole
}
void loop(void) {
u8g.setFont(u8g_font_6x10);
DateTime now = RTC.now();
Timer = now.hour(), DEC;
Minutt = now.minute(), DEC;
Sekund = now.second(), DEC;
Serial.print(Timer);
Serial.print(':');
Serial.print(Minutt);
Serial.print(':');
Serial.print(Sekund);
Serial.print(" - ");
an = now.year(), DEC;
Serial.print(an);
Serial.print('/');
luna = now.month(), DEC;
Serial.print(luna);
Serial.print('/');
zi = now.day(), DEC;
Serial.print(zi);
Serial.print(" (");
zis = now.dayOfTheWeek();
Serial.print(daysOfTheWeek[zis]);
Serial.println(") ");
moteur_pas();
// picture loop
u8g.firstPage();
do {
draw();
} while( u8g.nextPage() );
// rebuild the picture after some delay
delay(100);
pushlength = pushlengthset;
pushlength = getpushlength();
delay (10);
if (pushlength < pushlengthset)
{
//ShortPush ();
Serial.println("short push");
// picture loop
u8g.firstPage();
do {
draw1();
} while( u8g.nextPage() );
// rebuild the picture after some delay
delay(3000);
}
//This runs the setclock routine if the knob is pushed for a long time
if (pushlength > pushlengthset) {
// lcd.clear();
Serial.println("long push");
DateTime now = RTC.now();
setyeartemp=now.year(),DEC;
setmonthtemp=now.month(),DEC;
setdaytemp=now.day(),DEC;
setoretemp=now.hour(),DEC;
setminstemp=now.minute(),DEC;
setzitemp = now.dayOfTheWeek();
setclock();
pushlength = pushlengthset;
};
//}
} // end main loop
void moteur_pas(){
position_du_moteur = cptepas*5.6;
EEPROM.update(17,position_du_moteur);
{
if(position_du_moteur < alfa_1 - degrees_pas ){
monmoteur.step(+1); // Avance de 1 pas.
Serial.print("nombre de pas:" ); // Affiche dans le moniteur "série"
Serial.println(cptepas); // le nbre de pas effectué.
EEPROM.update(18,cptepas);
cptepas++; // Incrémente la variable cptepas pour compter les pas.
delay(500); // Pause d'une demi seconde entre chaque pas.
}
if(position_du_moteur > alfa_1 + degrees_pas){
monmoteur.step(-1);
Serial.print("nombre de pas:" ); // Affiche dans le moniteur "série"
Serial.println(cptepas); // le nbre de pas effectué.
EEPROM.update(18,cptepas);
cptepas--; // décrémente la variable cptepas pour compter les pas.
delay(500);
}
}
}
// subroutine to return the length of the button push.
int getpushlength()
{
buttonstate = digitalRead(A0);
if(buttonstate == LOW && buttonflag==false) {
pushstart = millis();
buttonflag = true;
};
if (buttonstate == HIGH && buttonflag==true) {
pushstop = millis ();
pushlength = pushstop - pushstart;
buttonflag = false;
};
Serial.println("_");
return pushlength;
}
void draw1(void) {
DateTime now = RTC.now();
// center
int x2=128/2;
int y2=64/2;
// radius
int r2=22;
// angle
int alfa_1 = 0;
maxday = EEPROM.read(7);
alfa_1=360*now.day()/maxday;
u8g.setPrintPos(1,10);
u8g.print(EEPROM.read(16));
u8g.setPrintPos(30,10);
u8g.print(EEPROM.read(17));
EEPROM.update(16,alfa_1);
u8g.setPrintPos(62,9);
u8g.print("0");
u8g.setPrintPos(90,32);
u8g.print("90");
u8g.setPrintPos(56,64);
u8g.print("180");
u8g.setPrintPos(22,32);
u8g.print("270");
u8g.drawLine(x2,y2, x2+r2*sin(1*alfa_1*2*3.14/360), y2-r2*cos(1*alfa_1*2*3.14/360));
u8g.drawCircle(x2, y2, r2);
}
//}
//sets the clock
void setclock (){
setyear ();//Annee
setmonth ();//Mois
setday ();//Jour
setzi();//semaine
setore ();//hours
setmins ();//Minutes
RTC.adjust(DateTime(setyeartemp,setmonthtemp,setdaytemp,setoretemp,setminstemp,setsecs));
CalcSun();
delay (1000);
}
int CalcSun () { //Calculates the Sunrise and Sunset times
DateTime now = RTC.now();
//Timelord initialisation
myLord.TimeZone(TIMEZONE * 60);
myLord.Position(LATITUDE, LONGITUDE);
sunTime[3] = now.day(); // Give Timelord the current date
sunTime[4] = now.month();
sunTime[5] = now.year();
myLord.SunRise(sunTime); // Computes Sun Rise.
Sunrise = sunTime[2] * 60 + sunTime[1]; // Sunrise returned in minutes past midnight
SunriseHour = sunTime[2];
SunriseMin = sunTime [1];
sunTime[3] = now.day(); // Uses the Time library to give Timelord the current date
sunTime[4] = now.month();
sunTime[5] = now.year();
myLord.SunSet(sunTime); // Computes Sun Set.
Sunset = sunTime[2] * 60 + sunTime[1]; // Sunset returned in minutes past midnight
SunsetHour = sunTime[2];
SunsetMin = sunTime [1];
uint16_t time = now.hour() * 60 + now.minute();
uint16_t angle = map(time, Sunrise, Sunset, 0, 180);
return angle;
if(angle < 0)
angle = 0;
else if(angle > 180)
angle = 180;
}
// The following subroutines set the individual clock parameters
int setyear () {
pushlength = pushlengthset;
pushlength = getpushlength ();
if (pushlength != pushlengthset) {
return setyeartemp;
}
knob.write(0);
delay (50);
knobval=knob.read();
if (knobval < -1) { //bit of software de-bounce
knobval = -1;
delay (50);
}
if (knobval > 1) {
knobval = 1;
delay (50);
}
setyeartemp=setyeartemp + knobval;
if (setyeartemp < 2018) { //Year can't be older than currently, it's not a time machine.
setyeartemp = 2018;
}
//itoa(setyeartemp - 2000, tmp_string, 10); // https://www.avrfreaks.net/forum/how-do-i-print-variable-u8glib
itoa(setyeartemp, tmp_string, 10); // https://www.avrfreaks.net/forum/how-do-i-print-variable-u8glib
u8g.firstPage();
do {
u8g.drawStr( 0, 20, "Set Annee");
// u8g.drawStr( 0, 40, "20");
u8g.drawStr(25, 40, tmp_string);
} while( u8g.nextPage() );
setyear();
}
int setmonth () {
pushlength = pushlengthset;
pushlength = getpushlength ();
if (pushlength != pushlengthset) {
return setmonthtemp;
}
// lcd.setCursor (0,1);
knob.write(0);
delay (50);
knobval=knob.read();
if (knobval < -1) {
knobval = -1;
}
if (knobval > 1) {
knobval = 1;
}
setmonthtemp=setmonthtemp + knobval;
if (setmonthtemp < 1) {// month must be between 1 and 12
setmonthtemp = 1;
}
if (setmonthtemp > 12) {
setmonthtemp=12;
}
itoa(setmonthtemp, tmp_string, 10);
u8g.firstPage();
do {
u8g.drawStr( 0, 20, "Set Mois");
u8g.drawStr(25, 40, tmp_string);
} while( u8g.nextPage() );
setmonth();
}
int setday () {
if (setmonthtemp == 4 || setmonthtemp == 5 || setmonthtemp == 9 || setmonthtemp == 11) { //30 days hath September, April June and November
maxday = 30;
}
else {
maxday = 31; //... all the others have 31
}
if (setmonthtemp ==2 && setyeartemp % 4 ==0) { //... Except February alone, and that has 28 days clear, and 29 in a leap year.
maxday = 29;
}
if (setmonthtemp ==2 && setyeartemp % 4 !=0) {
maxday = 28;
}
pushlength = pushlengthset;
pushlength = getpushlength ();
if (pushlength != pushlengthset) {
return setdaytemp;
}
knob.write(0);
delay (50);
knobval=knob.read();
if (knobval < -1) {
knobval = -1;
}
if (knobval > 1) {
knobval = 1;
}
setdaytemp = setdaytemp+ knobval;
if (setdaytemp < 1) {
setdaytemp = 1;
}
if (setdaytemp > maxday) {
setdaytemp = maxday;
}
itoa(setdaytemp, tmp_string, 10);
u8g.firstPage();
do {
u8g.drawStr( 0, 20, "Set Jour");
u8g.drawStr(25, 40, tmp_string);
} while( u8g.nextPage() );
setday();
}
int setzi () {
pushlength = pushlengthset;
pushlength = getpushlength ();
if (pushlength != pushlengthset) {
return setzitemp;
}
knob.write(0);
delay (50);
knobval=knob.read();
if (knobval < -1) {
knobval = -1;
}
if (knobval > 1) {
knobval = 1;
}
setzitemp=setzitemp + knobval;
if (setzitemp < 0) {// month must be between 0 and 6
setzitemp = 0;
}
if (setzitemp > 6) {
setzitemp=6;
}
itoa(setzitemp, tmp_string, 10);
u8g.firstPage();
do {
u8g.drawStr( 0, 20, "Set Jour of Week");
u8g.drawStr(25, 40, tmp_string);
u8g.drawStr(0,60, daysOfTheWeek[setzitemp]);
} while( u8g.nextPage() );
setzi();
}
int setore () {
pushlength = pushlengthset;
pushlength = getpushlength ();
if (pushlength != pushlengthset) {
return setoretemp;
}
knob.write(0);
delay (50);
knobval=knob.read();
if (knobval < -1) {
knobval = -1;
delay (50);
}
if (knobval > 1) {
knobval = 1;
delay (50);
}
setoretemp=setoretemp + knobval;
if (setoretemp < 0) {
setoretemp = 0;
}
if (setoretemp > 23) {
setoretemp=23;
}
itoa(setoretemp, tmp_string, 10);
u8g.firstPage();
do {
u8g.drawStr( 0, 20, "Set Heures");
u8g.drawStr(25, 40, tmp_string);
} while( u8g.nextPage() );
setore();
}
int setmins () {
pushlength = pushlengthset;
pushlength = getpushlength ();
if (pushlength != pushlengthset) {
return setminstemp;
}
knob.write(0);
delay (50);
knobval=knob.read();
if (knobval < -1) {
knobval = -1;
delay (50);
}
if (knobval > 1) {
knobval = 1;
delay (50);
}
setminstemp=setminstemp + knobval;
if (setminstemp < 0) {
setminstemp = 0;
}
if (setminstemp > 59) {
setminstemp=59;
}
itoa(setminstemp, tmp_string, 10);
u8g.firstPage();
do {
u8g.drawStr( 0, 20, "Set Minutes");
u8g.drawStr(25, 40, tmp_string);
} while( u8g.nextPage() );
setmins();
}












