voila sandro ,
je t'ai mis mon code complet .
merci de m'aider à faire le ménage .
bonne soirée.
#include <Wire.h>
#include <SPI.h>
#include "RTClib.h"
#include <TimeLib.h>
#include <math.h>
#include <stdlib.h>
#include <Encoder.h>
Encoder knob(2,3);// push(A0)
#include <EEPROM.h>
#include <TimeLord.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#include "Arduino.h"
#include "SI114X.h"
#include <avr/pgmspace.h>
#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;
SI114X SI1145 = SI114X();
char daysOfTheWeek[7][12] = {"Dim", "Lun", "Mar", "Mer", "Jeu", "Ven", "Sam"};
Adafruit_BME280 bme;
#define pressure_offset 12 // différence entre pression bme280 et pression météo locale
int frameCount = 5;
/* library ecran oled */
#include "U8glib.h"// V 1.17
/* différent type d'ecran*/
U8GLIB_SH1106_128X64 u8g(U8G_I2C_OPT_NONE); /*ecran sh1106 I2C*/
//U8GLIB_ST7920_128X64 u8g(13, 11, 12, U8G_PIN_NONE);
//U8GLIB_SSD1309_128X64 u8g(U8G_I2C_OPT_NONE);
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 // ................................................................................................................................
};
#define u8g_logo_width 16
#define u8g_logo_height 16
/*icones lune*/
static unsigned char u8g_LUNE_QUART_bits[] U8G_PROGMEM = {/* lune quart*/
0x00, 0x00, 0x00, 0x00, 0xc0, 0x03, 0x30, 0x0f, 0x08, 0x1f, 0x08, 0x1f, 0x04, 0x3f, 0x04, 0x3f, 0x04, 0x3f, 0x04, 0x3f, 0x08, 0x1f, 0x08, 0x1f, 0x30, 0x0f, 0xc0, 0x03, 0x00, 0x00, 0x00, 0x00
};
static unsigned char u8g_premier_croissant_bits[] U8G_PROGMEM = { /* premier croissant*/
0x00, 0x00, 0x00, 0x00, 0xc0, 0x03, 0x30, 0x0c, 0x08, 0x18, 0x08, 0x18, 0x04, 0x38, 0x04, 0x38, 0x04, 0x38, 0x04, 0x38, 0x08, 0x18, 0x08, 0x18, 0x30, 0x0c, 0xc0, 0x03, 0x00, 0x00, 0x00, 0x00
};
static unsigned char u8g_lune_dernier_croissant_bits[] U8G_PROGMEM = {/*dernier croissant*/
0x00, 0x00, 0x00, 0x00, 0xc0, 0x03, 0xf0, 0x0f, 0xc8, 0x1f, 0xc8, 0x1f, 0xc4, 0x3f, 0xc4, 0x3f, 0xc4, 0x3f, 0xc4, 0x3f, 0xc8, 0x1f, 0xc8, 0x1f, 0xf0, 0x0f, 0xc0, 0x03, 0x00, 0x00, 0x00, 0x00
};
static unsigned char u8g_lune_noir_bits[] U8G_PROGMEM = {/*lune noir*/
0x00, 0x00, 0x00, 0x00, 0xc0, 0x03, 0xf0, 0x0f, 0xf8, 0x1f, 0xf8, 0x1f, 0xfc, 0x3f, 0xfc, 0x3f, 0xfc, 0x3f, 0xfc, 0x3f, 0xf8, 0x1f, 0xf8, 0x1f, 0xf0, 0x0f, 0xc0, 0x03, 0x00, 0x00, 0x00, 0x00
};
static unsigned char u8g_pleine_LUNE_bits[] U8G_PROGMEM = {/*pleine lune*/
0x00, 0x00, 0x00, 0x00, 0xc0, 0x03, 0x30, 0x0c, 0x08, 0x10, 0x08, 0x10, 0x04, 0x20, 0x04, 0x20, 0x04, 0x20, 0x04, 0x20, 0x08, 0x10, 0x08, 0x10, 0x30, 0x0c, 0xc0, 0x03, 0x00, 0x00, 0x00, 0x00
};
static unsigned char u8g_premier_decroissant_bits[] U8G_PROGMEM = {/*premier decroissant*/
0x00, 0x00, 0x00, 0x00, 0xc0, 0x03, 0x30, 0x0c, 0x18, 0x10, 0x18, 0x10, 0x1c, 0x20, 0x1c, 0x20, 0x1c, 0x20, 0x1c, 0x20, 0x18, 0x10, 0x18, 0x10, 0x30, 0x0c, 0xc0, 0x03, 0x00, 0x00, 0x00, 0x00
};
static unsigned char u8g_quartier_decroissant_bits[] U8G_PROGMEM = {/*quartier decroissant*/
0x00, 0x00, 0x00, 0x00, 0xc0, 0x03, 0xf0, 0x0c, 0xf8, 0x10, 0xf8, 0x10, 0xfc, 0x20, 0xfc, 0x20, 0xfc, 0x20, 0xfc, 0x20, 0xf8, 0x10, 0xf8, 0x10, 0xf0, 0x0c, 0xc0, 0x03, 0x00, 0x00, 0x00, 0x00
};
static unsigned char u8g_dernier_decroissant_bits[] U8G_PROGMEM = {/*dernier decroissant*/
0x00, 0x00, 0x00, 0x00, 0xc0, 0x03, 0xf0, 0x0f, 0xf8, 0x13, 0xf8, 0x13, 0xfc, 0x23, 0xfc, 0x23, 0xfc, 0x23, 0xfc, 0x23, 0xf8, 0x13, 0xf8, 0x13, 0xf0, 0x0f, 0xc0, 0x03, 0x00, 0x00, 0x00, 0x00
};
/*icones Meteo*/
static unsigned char u8g_orageux_bits[] U8G_PROGMEM = {/*orageux*/
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x60, 0x03, 0x10, 0x02, 0x10, 0x3c, 0x1c, 0x20, 0x06, 0x40, 0xc2, 0x43, 0xc2, 0x21, 0xfc, 0x1f, 0xe0, 0x00, 0x60, 0x00, 0x20, 0x00
};
static unsigned char u8g_ensoleillee_bits[] U8G_PROGMEM = {/*ensoleillee*/
0x10, 0x00, 0x11, 0x01, 0xba, 0x00, 0x44, 0x00, 0xc6, 0x00, 0x64, 0x03, 0x1a, 0x02, 0x11, 0x3c, 0x1c, 0x20, 0x06, 0x40, 0x02, 0x40, 0x02, 0x20, 0xfc, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
static unsigned char u8g_pluie_bits[] U8G_PROGMEM = {/*pluie*/
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x60, 0x03, 0x10, 0x02, 0x10, 0x3c, 0x1c, 0x20, 0x06, 0x40, 0x02, 0x40, 0x02, 0x20, 0xfc, 0x1f, 0x00, 0x00, 0x20, 0x09, 0x90, 0x04
};
static unsigned char u8g_nuageux_bits[] U8G_PROGMEM = {/*nuageux*/
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x60, 0x03, 0x10, 0x02, 0x10, 0x3c, 0x1c, 0x20, 0x06, 0x40, 0x02, 0x40, 0x02, 0x20, 0xfc, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
static unsigned char u8g_sun_3_bits[] U8G_PROGMEM = {/* course 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
};
static unsigned char u8g_Sun_1_bits[] U8G_PROGMEM = {/*Animation Sun_1*/
0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0xe8, 0x0b, 0x10, 0x04, 0x08, 0x08, 0x08, 0x08, 0x0c, 0x18, 0x08, 0x08, 0x08, 0x08, 0x10, 0x04, 0xe8, 0x0b, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
static unsigned char u8g_Sun_2_bits[] U8G_PROGMEM = {/* Animation Sun_2*/
0x80, 0x00, 0x82, 0x20, 0x84, 0x10, 0xe8, 0x0b, 0x10, 0x04, 0x08, 0x08, 0x08, 0x08, 0x0f, 0x78, 0x08, 0x08, 0x08, 0x08, 0x10, 0x04, 0xe8, 0x0b, 0x84, 0x10, 0x82, 0x20, 0x80, 0x00, 0x00, 0x00
};
static unsigned char u8g_thermo_bits[] U8G_PROGMEM = {/*thermometre*/
0x00, 0x00, 0x00, 0x01, 0x80, 0x02, 0x80, 0x02, 0x80, 0x02, 0x80, 0x02, 0x80, 0x02, 0x80, 0x02, 0x80, 0x03, 0x80, 0x03, 0xc0, 0x07, 0xe0, 0x0f, 0xe0, 0x0f, 0xe0, 0x0f, 0xc0, 0x07, 0x80, 0x03
};
static unsigned char u8g_humidity_bits[] U8G_PROGMEM = {/*humidity*/
0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x80, 0x03, 0x80, 0x03, 0xc0, 0x07, 0xc0, 0x07, 0xe0, 0x0f, 0xe0, 0x0f, 0xe0, 0x0f, 0xc0, 0x07, 0x80, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
int Timer = 0;
int Minutt = 0;
int Sekund = 0;
float Vinkel = 0;
int an = 0;
int luna = 0;
int zi = 0;
int zis = 0;
/*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;
int Moon;
int setFuseautemp ;
int setLongitudetemp ;
int setLongitudetemp_1;
int setLatitudetemp ;
int setLatitudetemp_1;
/* state void draw ecran secondaire*/
int state = 0;
int val =0;
int old_buttonstate = 0;
/* cercle course du soleil*/
int r =35;//cercle drawLine
int r_1 = 35;//drawbitmap
int angle = 0;
int x1=57;// drawbitmap soleil rattrapage width 65-8 = 57
int y1=42;// drawbitmap soleil rattrapage height 50-8 = 42
int x0=65;
int y0=50;
int sun;
int adresse = 0;
/* variables stepper */
int degre = 0;
int stepper = 0;
int currentDegre = 0;
int currentDegre_1=0;
int degre_1 = 0;
int numstep;
/* pin stepper */
const int stepPin = 10;//~digitalwrite
const int dirPin = 12;//~digitalwrite
const int enPin = 11;//digitalwrite
// 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 knobval; // value for the rotation of the knob
boolean buttonflag = false; // default value for the button flag
char tmp_string[8];
unsigned long tpaprindere = 15000; // time for display something
unsigned long momentaprindere; // store time
float F_TIMEZONE = 0 ; /* UTC france = +1 Hiver +2 ete */
int TIMEZONE ;
float F_sunRhour=0,F_sunRmin =0;
int sunRhour, sunRmin;
float F_LATITUDE = 0,F_LATITUDE_1 = 0, F_LONGITUDE = 0,F_LONGITUDE_1 = 0;
float F_Long = 0, F_Lat = 0;
int LATITUDE ,LATITUDE_1, LONGITUDE,LONGITUDE_1, Long,Lat ;
//const float LATITUDE = 43.70, LONGITUDE = 7.25; // Nice Sun
String nfm = ""; // days to next full moon
int moonriseHour, moonriseMin, moonsetHour, moonsetMin;
int nowMin;
int time;
int margeAube,margeCrepuscule;
int heureMidi;
int Sunrise, Sunset,Sun_zenith ;
int minuit_lunaire_Min,lunaire_Min,minuit_lunaire_Hour,lunaire_Hour;
TimeLord myLord; // TimeLord Object, Global variable
byte current_season = 0;
byte sea = 0; // switch case saisons
byte SeasonTime[]={0,0,0,1,1,13};
byte my_Season ;
int SeasonHour,SeasonMin;
byte sunTime[] = {0, 0, 0, 1, 1, 13}; // 17 Oct 2013
int SunriseHour, SunriseMin, SunsetHour, SunsetMin,zenithHour,zenithMin,zenith,zenith_Hour,zenith_Min ;
#define PINPWMLUNE 8
int pwmLune = 0;
int valeur_Moon = 0;
int pwm2 = 5 ;// pwm Sun
int valeur_Sun = 0;
int pwm3 = 9;// pwm Horticole
//int backlight=6;//backlight control pin 6 "ST7920" sauf I2C
int overlaysCount = 1;
int frame = 0;// Animation Sun
//############################# EEPROM ######################################################################################################################################################################################################################################################################
// EEPROM 0 = soil_Min ,EEPROM 10 = soil_Max, EEPROM 1 = VOLUME ,EEPROM 2 = LONGITUDE degrés , EEPROM 3 = LATITUDE degrés, EEPROM 4 = TIMEZONE,EEPROM 5= longitude minutes , EEPROM 6 = LATITUDE minutes ,EEPROM 13 = angle soleil,EEPROM 22 = Degrés stepper, EEPROM 23 = Current_Degrés
//############################# Météo ########################################################################################################################################################################################################################################################################################
unsigned long delayTime;
String time_str, weather_text, weather_extra_text;
int last_reading_hour, reading_hour, hr_cnt;
enum image_names { // enumerated table used to point to images
rain_img, sunny_img, mostlysunny_img, cloudy_img, tstorms_img,
} image;
enum weather_type {unknown = 4,//inconnu
sunny = 2,// soleil
mostlysunny = 1,//assez ensoleillée
cloudy = 0,// nuageux
rain = -1,//pluie
tstorms = -2 //tempête
};
enum weather_description {GoodClearWeather, BecomingClearer,
NoChange, ClearSpells, ClearingWithin12hrs, ClearingAndColder,
GettingWarmer, WarmerIn2daysRainLikely,
ExpectRain, WarmerRainWithin36hrs, RainIn18hrs, RainHighWindsClearAndCool,
GalesHeavyRainSnowInWinter
};
weather_type current_wx;
/* An array structure to record pressure, temperature, humidity and weather state*/
typedef struct {
float pressure; // air pressure at the designated hour
float temperature; // temperature at the designated hour
float humidity; // humidity at the designated hour
weather_type wx_state_1hr; // weather state at 1-hour
weather_type wx_state_3hr; // weather state at 3-hour point
} wx_record_type;
wx_record_type reading[24]; // An array covering 24-hours to enable P, T, % and Wx state to be recorded for every hour
int wx_average_1hr, wx_average_3hr; // Indicators of average weather
bool look_3hr = true;
bool look_1hr = false;
float read_pressure(){
int reading = (bme.readPressure()/100.0F+pressure_offset)*10; // Rounded result to 1-decimal place
return (float)reading/10;
}
/* Convert pressure trend to text*/
String get_trend_text(float trend){
String trend_str = "Steady"; // Default weather state
if (trend > 3.5) { trend_str = "Rising fast"; }
else if (trend > 1.5 && trend <= 3.5) { trend_str = "Rising"; }
else if (trend > 0.25 && trend <= 1.5) { trend_str = "Rising slow"; }
else if (trend > -0.25 && trend < 0.25) { trend_str = "Steady"; }
else if (trend >= -1.5 && trend < -0.25) { trend_str = "Falling slow"; }
else if (trend >= -3.5 && trend < -1.5) { trend_str = "Falling"; }
else if (trend <= -3.5) { trend_str = "Falling fast"; }
return trend_str;
}
/* Convert forecast text to a corresponding image for display together with a record of the current weather*/
void ForecastToImgTxt(weather_description wx_text){
byte sel = 1;
if (wx_text == GoodClearWeather) {image = sunny_img; current_wx = sunny; weather_text = "Good clear weather"; sel = 1;}
else if (wx_text == BecomingClearer) {image = mostlysunny_img; current_wx = mostlysunny; weather_text = "Becoming clearer";sel = 2;}
else if (wx_text == NoChange) {image = cloudy_img; current_wx = cloudy; weather_text = "No change, clearing"; sel = 3;}
else if (wx_text == ClearSpells) {image = mostlysunny_img; current_wx = mostlysunny; weather_text = "Clear spells"; sel = 2;}
else if (wx_text == ClearingWithin12hrs) {image = mostlysunny_img; current_wx = mostlysunny; weather_text = "Clearing within 12-hrs";sel = 2;}
else if (wx_text == ClearingAndColder) {image = mostlysunny_img; current_wx = mostlysunny; weather_text = "Clearing and colder";sel = 2;}
else if (wx_text == GettingWarmer) {image = mostlysunny_img; current_wx = mostlysunny; weather_text = "Getting warmer";sel = 2;}
else if (wx_text == WarmerIn2daysRainLikely) {image = rain_img; current_wx = rain; weather_text = "Warmer in 2-days, rain likely";sel = 4;}
else if (wx_text == ExpectRain) {image = rain_img; current_wx = rain; weather_text = "Expect rain";sel = 2;}
else if (wx_text == WarmerRainWithin36hrs) {image = rain_img; current_wx = rain; weather_text = "Warmer, rain within 36-hrs";sel = 4;}
else if (wx_text == RainIn18hrs) {image = rain_img; current_wx = rain; weather_text = "Rain in 18-hrs";sel = 4;}
else if (wx_text == RainHighWindsClearAndCool) {image = rain_img; current_wx = rain; weather_text = "Rain, high winds, clear and cool";sel = 4;}
else if (wx_text == GalesHeavyRainSnowInWinter) {image = tstorms_img; current_wx = tstorms; weather_text = "Gales, heavy rain, in winter snow";sel = 5;}
/* Select Icon */
switch (sel) {
case 1: // Soleil
valeur_Sun = 255;/*100%*/
break;
case 2: // Ensoleillee
valeur_Sun = 191;/*75%*/
break;
case 3:// Nuageux
valeur_Sun = 128;/*50%*/
break;
case 4:// Pluie
valeur_Sun = 128;/*50%*/
break;
case 5:// Tempete
valeur_Sun = 64;/*25%*/
} // .end Switch Select
}
/* Convert pressure and trend to a weather description either for 1 or 3 hours with the boolean true/false switch*/
weather_description get_forecast_text(float pressure_now, float trend, bool range) {
String trend_str = get_trend_text(trend);
weather_description wx_text = NoChange; //As a default forecast
weather_extra_text = "";
//image = cloudy_img; // Generally when there is 'no change' then cloudy is the conditions
if (pressure_now >= 1022.68 ) {wx_text = GoodClearWeather;}
if (pressure_now >= 1022.7 && trend_str == "Falling fast") {wx_text = WarmerRainWithin36hrs;}
if (pressure_now >= 1013.2 && pressure_now <= 1022.68 &&
(trend_str == "Steady" || trend_str == "Rising slow")) {wx_text = NoChange; (range?wx_history_3hr():wx_history_1hr()); }
if (pressure_now >= 1013.2 && pressure_now <= 1022.68 &&
(trend_str == "Rising" || trend_str == "Rising fast")) {wx_text = GettingWarmer;}
if (pressure_now >= 1013.2 && pressure_now <= 1022.68 && trend_str == "Rising slow") {wx_text = BecomingClearer;}
if (pressure_now >= 1013.2 && pressure_now <= 1022.68 &&
(trend_str == "Falling fast" || trend_str == "Faling slow")) {wx_text = ExpectRain;}
if (pressure_now >= 1013.2 && pressure_now <= 1022.68 && trend_str == "Steady") {wx_text = ClearSpells; (range?wx_history_3hr():wx_history_1hr());};
if (pressure_now <= 1013.2 && (trend_str == "Falling slow" || trend_str == "Falling")) {wx_text = RainIn18hrs;}
if (pressure_now <= 1013.2 && trend_str == "Falling fast") {wx_text = RainHighWindsClearAndCool;}
if (pressure_now <= 1013.2 &&
(trend_str == "Rising" || trend_str=="Rising slow"||trend_str=="Rising fast")) {wx_text = ClearingWithin12hrs;}
if (pressure_now <= 1009.14 && trend_str == "Falling fast") {wx_text = GalesHeavyRainSnowInWinter;}
if (pressure_now <= 1009.14 && trend_str == "Rising fast") {wx_text = ClearingAndColder;}
return wx_text;
}
/* Convert 1-hr weather history to text*/
void wx_history_1hr() {
if (wx_average_1hr > 0) weather_extra_text = ", expect sun";
else if (wx_average_1hr == 0) weather_extra_text = ", mainly cloudy";
else if (wx_average_1hr < 0) weather_extra_text = ", expect rain";
else weather_extra_text = "";
}
/* Convert 3-hr weather history to text*/
void wx_history_3hr() {
if (wx_average_3hr > 0) weather_extra_text = ", expect sun";
else if (wx_average_3hr == 0) weather_extra_text = ", mainly cloudy";
else if (wx_average_3hr < 0) weather_extra_text = ", expect rain";
else weather_extra_text = "";
}
/* Moon Calcul */
static float Dec[3] = { 0.0, 0.0, 0.0 };
static float RAn[3] = { 0.0, 0.0, 0.0 };
static float VHz[3] = { 0.0, 0.0, 0.0 };
static float Sky[3] = { 0.0, 0.0, 0.0 };
const static float DR = M_PI / 180;
static int Rise_time[2] = {0.0, 0.0};
static int Set_time[2] = {0.0, 0.0};
static bool Moonrise, Moonset;
/* returns value for sign of argument*/
float sgn(float x)
{
float rv;
if (x > 0.0)
rv = 1;
else if (x < 0.0)
rv = -1;
else
rv = 0;
return rv;
}
/* determine Julian day from calendar date (Jean Meeus, "Astronomical Algorithms", Willmann-Bell, 1991)*/
float julian_day(const int day_const, const int month_const,
const int year_const)
{
float a, b, jd;
bool gregorian;
int month = month_const;
int day = day_const;
float year = (float) year_const;
gregorian = (year < 1583) ? 0 : 1;
if ((month == 1) || (month == 2)) {
year = year - 1;
month = month + 12;
}
a = floor(year / 100);
if (gregorian)
b = 2.0 - a + floor(a / 4.0);
else
b = 0.0;
jd = floor(365.25 * (float)(year + 4716.0))
+ floor(30.6001 * (float)(month + 1))
+ day + b - 1524.5;
return jd;
}
/* moon's position using fundamental arguments (Van Flandern & Pulkkinen, 1979)*/
void moon(float jd)
{
float d, f, g, h, m, n, s, u, v, w;
h = 0.606434 + 0.03660110129 * jd;
m = 0.374897 + 0.03629164709 * jd;
f = 0.259091 + 0.0367481952 * jd;
d = 0.827362 + 0.03386319198 * jd;
n = 0.347343 - 0.00014709391 * jd;
g = 0.993126 + 0.0027377785 * jd;
h = h - floor(h);
m = m - floor(m);
f = f - floor(f);
d = d - floor(d);
n = n - floor(n);
g = g - floor(g);
h = h * 2 * M_PI;
m = m * 2 * M_PI;
f = f * 2 * M_PI;
d = d * 2 * M_PI;
n = n * 2 * M_PI;
g = g * 2 * M_PI;
v = 0.39558 * sin(f + n);
v = v + 0.082 * sin(f);
v = v + 0.03257 * sin(m - f - n);
v = v + 0.01092 * sin(m + f + n);
v = v + 0.00666 * sin(m - f);
v = v - 0.00644 * sin(m + f - 2 * d + n);
v = v - 0.00331 * sin(f - 2 * d + n);
v = v - 0.00304 * sin(f - 2 * d);
v = v - 0.0024 * sin(m - f - 2 * d - n);
v = v + 0.00226 * sin(m + f);
v = v - 0.00108 * sin(m + f - 2 * d);
v = v - 0.00079 * sin(f - n);
v = v + 0.00078 * sin(f + 2 * d + n);
u = 1 - 0.10828 * cos(m);
u = u - 0.0188 * cos(m - 2 * d);
u = u - 0.01479 * cos(2 * d);
u = u + 0.00181 * cos(2 * m - 2 * d);
u = u - 0.00147 * cos(2 * m);
u = u - 0.00105 * cos(2 * d - g);
u = u - 0.00075 * cos(m - 2 * d + g);
w = 0.10478 * sin(m);
w = w - 0.04105 * sin(2 * f + 2 * n);
w = w - 0.0213 * sin(m - 2 * d);
w = w - 0.01779 * sin(2 * f + n);
w = w + 0.01774 * sin(n);
w = w + 0.00987 * sin(2 * d);
w = w - 0.00338 * sin(m - 2 * f - 2 * n);
w = w - 0.00309 * sin(g);
w = w - 0.0019 * sin(2 * f);
w = w - 0.00144 * sin(m + n);
w = w - 0.00144 * sin(m - 2 * f - n);
w = w - 0.00113 * sin(m + 2 * f + 2 * n);
w = w - 0.00094 * sin(m - 2 * d + g);
w = w - 0.00092 * sin(2 * m - 2 * d);
s = w / sqrt(u - v * v); // compute moon's right ascension ...
Sky[0] = h + atan(s / sqrt(1 - s * s));
s = v / sqrt(u); // declination ...
Sky[1] = atan(s / sqrt(1 - s * s));
Sky[2] = 60.40974 * sqrt(u); // and parallax
}
/* test an hour for an event*/
float test_moon(int k, float t0, float lat, float plx)
{
const static float K1 = 15 * M_PI * 1.0027379 / 180;
static float Rise_az = 0.0, Set_az = 0.0;
float ha[3] = { 0.0, 0.0, 0.0 };
float a, b, c, d, e, s, z;
float hr, min, time;
float az, hz, nz, dz;
if (RAn[2] < RAn[0])
RAn[2] = RAn[2] + 2 * M_PI;
ha[0] = t0 - RAn[0] + (k * K1);
ha[2] = t0 - RAn[2] + (k * K1) + K1;
ha[1] = (ha[2] + ha[0]) / 2; // hour angle at half hour
Dec[1] = (Dec[2] + Dec[0]) / 2; // declination at half hour
s = sin(DR * lat);
c = cos(DR * lat);
/* refraction + sun semidiameter at horizon + parallax correction*/
z = cos(DR * (90.567 - 41.685 / plx));
if (k <= 0) // first call of function
VHz[0] = s * sin(Dec[0]) + c * cos(Dec[0]) * cos(ha[0]) - z;
VHz[2] = s * sin(Dec[2]) + c * cos(Dec[2]) * cos(ha[2]) - z;
if (sgn(VHz[0]) == sgn(VHz[2]))
return VHz[2]; // no event this hour
VHz[1] = s * sin(Dec[1]) + c * cos(Dec[1]) * cos(ha[1]) - z;
a = 2 * VHz[2] - 4 * VHz[1] + 2 * VHz[0];
b = 4 * VHz[1] - 3 * VHz[0] - VHz[2];
d = b * b - 4 * a * VHz[0];
if (d < 0)
return VHz[2]; /* no event this hour*/
d = sqrt(d);
e = (-b + d) / (2 * a);
if ((e > 1) || (e < 0))
e = (-b - d) / (2 * a);
time = ((float) k) + e + 1 / 120; /* time of an event + round up*/
hr = floor(time);
min = floor((time - hr) * 60);
hz = ha[0] + e * (ha[2] - ha[0]); /* azimuth of the moon at the event*/
nz = -cos(Dec[1]) * sin(hz);
dz = c * sin(Dec[1]) - s * cos(Dec[1]) * cos(hz);
az = atan2(nz, dz) / DR;
if (az < 0)
az = az + 360;
if ((VHz[0] < 0) && (VHz[2] > 0)) {
Rise_time[0] = (int) hr;
Rise_time[1] = (int) min;
Rise_az = az;
Moonrise = 1;
}
if ((VHz[0] > 0) && (VHz[2] < 0)) {
Set_time[0] = (int) hr;
Set_time[1] = (int) min;
Set_az = az;
Moonset = 1;
}
return VHz[2];
}
/* Local Sidereal Time for zone*/
float lst(const float lon, const float jd, const float z)
{
float s =
24110.5 + 8640184.812999999 * jd / 36525 + 86636.6 * z +
86400 * lon;
s = s / 86400;
s = s - floor(s);
return s * 360 * DR;
}
/* 3-point interpolation*/
float interpolate(const float f0, const float f1, const float f2,
const float p)
{
float a = f1 - f0;
float b = f2 - f1 - a;
float f = f0 + p * (2 * a + b * (2 * p - 1));
return f;
}
/* calculate moonrise and moonset times*/
void riseset(const float lat, const float lon, const int day,
const int month, const int year, const int TIMEZONE )//
{
int i, j, k;
float ph;
// guido: julian day has been converted to int from float
// float jd = (julian_day(day, month, year)) - 2451545; // Julian day relative to Jan 1.5, 2000
float jd = (julian_day(day, month, year)) - 2451545; // Julian day relative to Jan 1.5, 2000
float mp[3][3];
float lon_local = lon;
if ((sgn(-TIMEZONE) == sgn(lon)) && (TIMEZONE != 0))//
Serial.println("WARNING: time zone and longitude are incompatible!");
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++)
mp[i][j] = 0.0;
}
lon_local = lon / 360;
float tz = -((float)TIMEZONE) / 24;
float t0 = lst(lon_local, jd, tz); /* local sidereal time*/
jd = jd + tz; /* get moon position at start of day*/
for (k = 0; k < 3; k++) {
moon(jd);
mp[k][0] = Sky[0];
mp[k][1] = Sky[1];
mp[k][2] = Sky[2];
jd = jd + 0.5;
}
if (mp[1][0] <= mp[0][0])
mp[1][0] = mp[1][0] + 2 * M_PI;
if (mp[2][0] <= mp[1][0])
mp[2][0] = mp[2][0] + 2 * M_PI;
RAn[0] = mp[0][0];
Dec[0] = mp[0][1];
Moonrise = 0; /* initialize*/
Moonset = 0;
for (k = 0; k < 24; k++) /* check each hour of this day*/
{
ph = ((float) (k + 1)) / 24;
RAn[2] = interpolate(mp[0][0], mp[1][0], mp[2][0], ph);
Dec[2] = interpolate(mp[0][1], mp[1][1], mp[2][1], ph);
VHz[2] = test_moon(k, t0, lat, mp[1][2]);
RAn[0] = RAn[2]; // advance to next hour
Dec[0] = Dec[2];
VHz[0] = VHz[2];
}
}
float get_phase(const DateTime now, const int TIMEZONE) {/*TZOffset*/
//float phase = (julian_day(now.day(),now.month(), now.year()) - 2451550.1);
//float phase = (julian_day(now.day(),now.month(), now.year()) - 2440594.359028); //CE 1970 January 07 20:37:00.2 UT Wednesday - new moon
float phase;
phase = julian_day(now.day(),now.month(), now.year());
// phase -= 2455211.8; //CE 2010 January 15 07:12:00.0 UT - new moon
phase -= 2440594.359028;
phase += ((now.hour() * 60) + now.minute()) / (float)1440; // Adjust for current time JD returns Midnight. 1140 = minutes in day.
phase += -((float)TIMEZONE) / 24.0; // Now adjust local to UTC.
phase = fmod(phase,29.530588853);
return (phase);
}
/* check for no moonrise and/or no moonset*/
int moon_up(const DateTime now) {
int riseMin=(Rise_time[0]*60)+Rise_time[1];
int setMin=(Set_time[0]*60)+Set_time[1];
int nowMin=(now.hour()*60)+now.minute();
if ((!Moonrise) && (!Moonset)) { // neither moonrise nor moonset
if (VHz[2] < 0)
return(0); // down all day
else
return(1); // up all day
}
if (Moonrise && Moonset) {
if ((setMin > riseMin) && (riseMin < nowMin) && (nowMin < setMin)) {
return(1); // up
}
if ((setMin < riseMin) && ((nowMin < setMin) || (nowMin > riseMin))) {
return(1); // up
}
}
if (Moonrise && (!Moonset)) { // Moonrise only
if (nowMin > riseMin) {
return(1);
}
}
if (Moonset && (!Moonrise)) { // Moonset only
if (nowMin < setMin) {
return(1);
}
}
return(0); // if in doubt turn blow it out
}
int moon_phase(){
/* calculates the age of the moon phase(0 to 7)*/
/* there are eight stages, 0 is full moon and 4 is a new moon*/
DateTime now = RTC.now();
double jd = 0; // Julian Date
double ed = 0; //days elapsed since start of full moon
int b= 0;
jd = julianDate(now.year(), now.month(), now.day());
//jd = julianDate(1972,1,1); // used to debug this is a new moon
jd = int(jd - 2244116.75); // start at Jan 1 1972
jd /= 29.53; // divide by the moon cycle
b = jd;
jd -= b; // leaves the fractional part of jd
ed = jd * 29.53; // days elapsed this month
nfm = String((int(29.53 - ed))); // days to next full moon
b = jd*8 +0.5;
b = b & 7;
return b;
}
double julianDate(int y, int m, int d){
/* convert a date to a Julian Date}*/
int mm,yy;
double k1, k2, k3;
double j;
yy = y- int((12-m)/10);
mm = m+9;
if(mm >= 12) {
mm = mm-12;
}
k1 = 365.25 *(yy +4172);
k2 = int((30.6001 * mm) + 0.5);
k3 = int((((yy/100) + 4) * 0.75) -38);
j = k1 +k2 + d + 59;
j = j-k3; // j is the Julian date at 12h UT (Universal Time)
return j;
}
void Affichage_Sun(void){
DateTime now = RTC.now();
TimeMins = (now.hour() * 60) + now.minute();
if(TimeMins>Sunset&&TimeMins<Sunrise){
/*Affichage heure Sunrise*/
u8g.setFont(u8g_font_6x10);
u8g.setPrintPos(80,20);
if(SunriseHour<10);
u8g.print("0");
u8g.print(SunriseHour);
u8g.print (":");
if (SunriseMin <10)
u8g.print("0");
u8g.print (SunriseMin);
}
if(TimeMins>Sunrise&&TimeMins<heureMidi){
/* affichage heure zenith*/
u8g.setFont(u8g_font_6x10);
u8g.setPrintPos(80,20 );
if(zenith_Hour<0)
u8g.print("0");
u8g.print(zenith_Hour);
u8g.print(":");
if (zenith_Min<10)
u8g.print("0");
u8g.print (zenith_Min);
}
if(TimeMins>heureMidi&&TimeMins>Sunrise){
/*Affichage heure Sunset*/
u8g.setFont(u8g_font_6x10);
u8g.setPrintPos(80,20);
if(SunsetHour<10)
u8g.print("0");
u8g.print (SunsetHour);
u8g.print (":");
if (SunsetMin <10)
u8g.print("0");
u8g.print (SunsetMin);
}
}
void Affichage_Moon(void){
DateTime now = RTC.now();
TimeMins = (now.hour() * 60) + now.minute();
int riseMin=(Rise_time[0]*60)+Rise_time[1];
int setMin=(Set_time[0]*60)+Set_time[1];
int minuitLunaire = (riseMin + setMin)/2 ;
if(TimeMins>Moonset&&TimeMins<Moonrise){
/*Affichage heure Moonrise*/
u8g.setFont(u8g_font_6x10);
u8g.setPrintPos(80,30 );
if(moonriseHour<10)
u8g.print("0");
u8g.print(moonriseHour);
u8g.print(":");
if (moonriseMin <10)
u8g.print("0");
u8g.print (moonriseMin);
}
if(TimeMins> Moonrise && TimeMins<minuitLunaire){
/* affichage minuit lunaire*/
u8g.setFont(u8g_font_6x10);
u8g.setPrintPos(80,30 );
if(lunaire_Hour<0)
u8g.print("0");
u8g.print(lunaire_Hour);
u8g.print(":");
if (lunaire_Min<10)
u8g.print("0");
u8g.print (lunaire_Min);
}
if(TimeMins>minuitLunaire && TimeMins> Moonrise){
/*Affichage heure Moonset*/
u8g.setFont(u8g_font_6x10);
u8g.setPrintPos(80,30);
if(moonsetHour<10)
u8g.print("0");
u8g.print (moonsetHour);
u8g.print (":");
if (moonsetMin <10)
u8g.print("0");
u8g.print (moonsetMin);
}
}
void drawMoon(void){
DateTime now = RTC.now();
time = ((now.hour() * 100) + now.minute());
int mp = moon_phase();
switch (mp){
case 0:
u8g.setFont(u8g_font_04b_03);
u8g.setPrintPos(2,51);
valeur_Moon = 255;/* 100% Pleine Lune*/
break;
case 1:
u8g.setFont(u8g_font_04b_03);
u8g.setPrintPos(2,51);
valeur_Moon = 191;/* 75% lune gibbeuse croissante*/
break;
case 2:
u8g.setFont(u8g_font_04b_03);
u8g.setPrintPos(2,51);
valeur_Moon = 128;/* 50% premier quartier de lune */
break;
case 3:
u8g.setFont(u8g_font_04b_03);
u8g.setPrintPos(2,51);
valeur_Moon = 64;/* 25% lune premier croissant*/
break;
case 4:
u8g.setFont(u8g_font_04b_03);
u8g.setPrintPos(2,51);
valeur_Moon = 0;/*0% lune noir */
break;
case 5:
u8g.setFont(u8g_font_04b_03);
u8g.setPrintPos(2,51);
valeur_Moon = 64;/*25% dernier croissant */
break;
case 6:
u8g.setFont(u8g_font_04b_03);
u8g.setPrintPos(2,51);
valeur_Moon = 128;/*50% dernier quartier */
break;
case 7:
u8g.setFont(u8g_font_04b_03);
u8g.setPrintPos(2,51);
valeur_Moon = 191;/*75% premier decroissant*/
break;
}
const char* newNfm = (const char*) nfm.c_str();
}
void print_time(const DateTime now) {
Serial.print(now.year(), DEC);
Serial.print('/');
if (now.year() < 10)
Serial.print("0");
Serial.print(now.month(), DEC);
Serial.print('/');
if (now.day() < 10)
Serial.print("0");
Serial.print(now.day(), DEC);
Serial.print(' ');
if (now.hour() < 10)
Serial.print("0");
Serial.print(now.hour(), DEC);
Serial.print(':');
if (now.minute() < 10)
Serial.print("0");
Serial.print(now.minute(), DEC);
Serial.print(':');
if (now.second() < 10)
Serial.print("0");
Serial.print(now.second(), DEC);
}
void print_moonrise (void) {
if (Moonrise) {
if (Rise_time[0] < 10) {
Serial.print("0");
}
Serial.print(Rise_time[0]);
Serial.print(":");
if (Rise_time[1] < 10) {
Serial.print("0");
}
Serial.print(Rise_time[1]);
} else {
Serial.print(" none");
}
}
void print_moonset (void) {
if (Moonset) {
if (Set_time[0] < 10) {
Serial.print("0");
}
Serial.print(Set_time[0]);
Serial.print(":");
if (Set_time[1] < 10) {
Serial.print("0");
}
Serial.print(Set_time[1]);
} else {
Serial.print(" none");
}
}
void print_phase(const DateTime now) {
Serial.print(get_phase(now, TIMEZONE),4);
}
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];
int riseMin=(Rise_time[0]*60)+Rise_time[1];
int setMin=(Set_time[0]*60)+Set_time[1];
int minuit_lunaire_Min=(riseMin+setMin)/2;
zenithMin = (Sunset+Sunrise)/2;
zenith_Min = (zenithMin)%60;
zenithHour = (Sunset+Sunrise)/2;
zenith_Hour = (zenithHour)/60;
minuit_lunaire_Min =(riseMin+setMin)/2;
lunaire_Min = (minuit_lunaire_Min)%60;
minuit_lunaire_Hour =(riseMin+setMin)/2;
lunaire_Hour = (minuit_lunaire_Hour)/60;
TimeMins = (now.hour() * 60) + now.minute();
uint16_t time = now.hour() * 60 + now.minute();
uint16_t angle = map(time, Sunrise, Sunset, 0, 180);
Affichage_Sun();
Affichage_Moon();
setPwmLune();
/*evite de depasser l'angle*/
if(angle < 0)
angle = 0;
else if(angle > 180)
angle = 180;
EEPROM.update(13,angle);//Angle du soleil info ecran secondaire
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*/
/* pwm Sunrise/Sunset Jaune */
if(TimeMins < heureMidi ){
pwm2 = map ( TimeMins, Sunrise - margeAube, heureMidi, 0, valeur_Sun);
}
else {
pwm2 = map ( TimeMins, heureMidi, Sunset + margeCrepuscule, valeur_Sun, 0);
}
if(pwm2<0) {
pwm2=0;
}
analogWrite(5,pwm2);/* PIN 5 timer 16 bits*/
/* pwm Sunrise/Sunset Horticole */
if(TimeMins < heureMidi ){
pwm3 = map ( TimeMins, Sunrise, heureMidi, 0, valeur_Sun);
}
else {
pwm3 = map ( TimeMins, heureMidi, Sunset, valeur_Sun, 0);
}
if(pwm3<0) {
pwm3=0;
}
analogWrite(9,pwm3);/* PIN 9 timer 8 bits*/
myLord.Season(SeasonTime);// Computes Season
SeasonTime[2]= SeasonHour;
SeasonTime[1]= SeasonMin;
SeasonTime[3] = now.day();
SeasonTime[4] = now.month();
SeasonTime[5] = now.year();
SeasonHour = now.hour();
SeasonMin = now.minute();
/* Computes Season */
current_season = myLord.Season(SeasonTime);
if (current_season == 0){sea=0;}
if (current_season == 1){sea=1;}
if (current_season == 2){sea=2;}
if (current_season == 3){sea=3;}
/* Select Icon*/
switch (sea) {
case 0: // Hiver
u8g.setFont(u8g_font_6x10);
u8g.setPrintPos(75,40);
u8g.print("Hiver ");
break;
case 1: // Printemps
u8g.setFont(u8g_font_6x10);
u8g.setPrintPos(75,40);
u8g.print("Printemps");
break;
case 2:// Eté
u8g.setFont(u8g_font_6x10);
u8g.setPrintPos(75,40);
u8g.print("Ete ");
break;
case 3:// Automne
u8g.setFont(u8g_font_6x10);
u8g.setPrintPos(75,40);
u8g.print("Automne ");
} // .end Switch Select
/* date mois jour * Rectif Heure */
u8g.setFont(u8g_font_6x13);
u8g.setPrintPos(2,10);
if (now.day() < 10) u8g.print("0");
u8g.print(now.day());
u8g.print("/");
if (now.month() < 10) u8g.print("0");
u8g.print(now.month());
u8g.print("/");
u8g.setPrintPos(40,10);
u8g.print(daysOfTheWeek[zis]);
u8g.setFont(u8g_font_6x13);
u8g.setPrintPos(80,10);
if (now.hour() < 10) u8g.print("0");
u8g.print(now.hour());
u8g.setPrintPos(92,10);
if (now.second()%2 != 1)
u8g.print(":");
u8g.setPrintPos(112,10);
u8g.setFont(u8g_font_6x10);
if(now.second()<10)u8g.print("0");
u8g.print(now.second());
u8g.setPrintPos(98,10);
u8g.setFont(u8g_font_6x13);
if (now.minute() < 10) u8g.print("0");
u8g.print(now.minute());
/* affichage angle Draw_soleil */
u8g.setFont(u8g_font_6x10);
u8g.setPrintPos(2,60 );
u8g.print("angle: ");// soleil
u8g.setPrintPos(50,60 );
u8g.print(angle);//soleil
/* Affichage pwm */
u8g.setFont(u8g_font_6x10);
u8g.setPrintPos(0,20);
u8g.print("Sun: ");
u8g.print(pwm2);
u8g.setPrintPos(0,40);
u8g.print("Hort: ");
u8g.print(pwm3);
/* affichage angle_Stepper */
u8g.setFont(u8g_font_6x10);
u8g.setPrintPos(80,60 );
u8g.print("st: ");// stepper
u8g.setPrintPos(100,60 );
u8g.print(degre);//stepper
TimeMins = (now.hour() * 60) + now.minute();
/*If it's after sunrise and before sunset, switch our relay on*/
if (TimeMins >= Sunrise && TimeMins <=Sunset-1) {
//digitalWrite (A3, HIGH);// Relay
//analogWrite(backlight,255);/* lcd rétroéclairage On st7920*/
//u8g.setColorIndex(1); /* Pixel On sh1103*/
}
else { /*otherwise switch it off*/
//digitalWrite (A3,LOW);//Relay
//analogWrite(backlight,0);/* lcd rétroéclairage Off st7920*/
//u8g.setColorIndex(0);/* Pixel Off sh1103*/
}
/* forecast meteo*/
reading_hour = now.hour();
if (reading_hour != last_reading_hour) { // If the hour has advanced, then shift readings left and record new values at array element [23]
for (int i = 0; i < 23;i++){
reading[i].pressure = reading[i+1].pressure;
reading[i].temperature = reading[i+1].temperature;
reading[i].wx_state_1hr = reading[i+1].wx_state_1hr;
reading[i].wx_state_3hr = reading[i+1].wx_state_3hr;
}
reading[23].pressure = read_pressure(); // Update time=now with current value of pressure
reading[23].wx_state_1hr = current_wx;
reading[23].wx_state_3hr = current_wx;
last_reading_hour = reading_hour;
hr_cnt++;
wx_average_1hr = reading[22].wx_state_1hr + current_wx; // Used to predict 1-hour forecast extra text
wx_average_3hr = 0;
for (int i=23;i >= 21; i--){ // Used to predict 3-hour forecast extra text
wx_average_3hr = wx_average_3hr + (int)reading[i].wx_state_3hr; // On average the last 3-hours of weather is used for the 'no change' forecast - e.g. more of the same?
}
}
// ForecastToImgTxt(get_forecast_text(reading[23].pressure, trend, look_3hr));
// weather_description wx_text = get_forecast_text(reading[23].pressure, trend, look_3hr);
reading[23].pressure = (reading[23].pressure + read_pressure())/2; /* 1hr */ // Update rolling average, gets reset on the hour transition
float trend = reading[23].pressure - reading[20].pressure; /* 3hr */ // Get short-term trend for the last 3-hour
weather_description wx_text = get_forecast_text(read_pressure(), trend, look_1hr);
ForecastToImgTxt(wx_text); /* 1hr &3hr*/
/* affichage pression hpa*/
u8g.setFont(u8g_font_6x10);
u8g.setPrintPos(2,50);
u8g.print("hpa: ");
u8g.setPrintPos(30,50);
u8g.print(read_pressure());
}
int calculPwm( int TimeMins, int riseMin, int setMin) {
DateTime now = RTC.now();
TimeMins = (now.hour() * 60) + now.minute();
riseMin = Rise_time[0] * 60 + Rise_time[1];
setMin = Set_time[0]*60 + Set_time[1];
int pwm = 0;
int minuitLunaire = 0;
int minuit_lunaire_Min=(riseMin+setMin)/2;
minuit_lunaire_Min =(riseMin+setMin)/2;
lunaire_Min = (minuit_lunaire_Min)%60;
minuit_lunaire_Hour =(riseMin+setMin)/2;
lunaire_Hour = (minuit_lunaire_Hour)/60;
// gestion du cas où le levé est plus tard que le couché pour la lune
if( riseMin > setMin)
setMin+= 24 * 60; // ajout de 24h...
//minuitLunaire = minuitLunaire *2;// ajout de 24h...
if( TimeMins < riseMin )
TimeMins += 24 * 60; // ajout de 24h...
// fin de la gestion
minuitLunaire=(riseMin+setMin)/2;
/* phase montante*/
if(TimeMins > riseMin && TimeMins <minuitLunaire) {//<=au lieu de <
pwm = map( TimeMins, riseMin,minuitLunaire , 0, valeur_Moon);
}
/* phase descendante */
if(TimeMins > minuitLunaire && TimeMins < setMin) {
pwm = map( TimeMins, minuitLunaire, setMin, valeur_Moon, 0);
}
return pwm;
}
void setPwmLune() {
DateTime now = RTC.now();
TimeMins = (now.hour() * 60) + now.minute();
int riseMin = Rise_time[0] * 60 + Rise_time[1]; // Attention variables globales à modifier avec des fonctions...
int setMin = Set_time[0]*60 + Set_time[1]; // Attention variables globales ...
int pwmLune = calculPwm ( TimeMins, riseMin, setMin );
u8g.setFont(u8g_font_6x10);
u8g.setPrintPos(0,30);
u8g.print("Lune: ");
u8g.print(pwmLune);
analogWrite(PINPWMLUNE, pwmLune);
}
void setup(void) {
draw_Bonsai();//Boot Bitmap logo
//analogWrite(backlight, 255);/*Retroeclairage PIN 6 */
delay(5000);
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__)));
}
/*Timelord initialisation*/
myLord.TimeZone(TIMEZONE * 60);
myLord.Position(LATITUDE, LONGITUDE);
CalcSun ();
Wire.begin();
SI1145.Begin();
float p,t;
Serial.println(F("BME280 test"));
bool status;
/* default settings*/
status = bme.begin(0x76);
if (!status) {
Serial.println("Could not find a valid BME280 sensor, check wiring!");
while (isnan(bme.readPressure())) { Serial.println(bme.readPressure());
} //while (1);
delayTime = 1000;
}
DateTime();
for (int i = 0; i <= 23; i++){ // At the start all array values are the same as a baseline
reading[i].pressure = read_pressure(); // A rounded to 1-decimal place version of pressure
reading[i].temperature = bme.readTemperature(); // Although not used, but avialable
reading[i].humidity = bme.readHumidity(); // Although not used, but avialable for BMP280
reading[i].wx_state_1hr = unknown; // To begin with
reading[i].wx_state_3hr = unknown; // To begin with
} // Note that only 0,5,11,17,20,21,22,23 are used as display positions
last_reading_hour = reading_hour;
wx_average_1hr = 0; // Until we get a better idea
wx_average_3hr = 0; // Until we get a better idea
/* pins assignation*/
/*push button on encoder connected to A0 (and GND)*/
pinMode(A0,INPUT);
digitalWrite(A0,HIGH);
/* pin PWM blanche Sun*/
pinMode (5,OUTPUT);
analogWrite(pwm2,LOW);// commande pwm Jaune Sun
/* pin PWM bleu lune*/
pinMode (8,OUTPUT);
analogWrite(PINPWMLUNE,LOW);// commande pwm bleu lune PINPWMLUNE
/* pin pwm horticole*/
pinMode (9,OUTPUT);
analogWrite(pwm3,LOW);// commande pwm blanche rouge Horticole
// Pins commande stepper
pinMode(stepPin,OUTPUT);//10
pinMode(dirPin,OUTPUT); //12
pinMode(enPin,OUTPUT); //11
digitalWrite(dirPin,HIGH);
}
void drawFrame1() {// forescast météo
float trend = reading[23].pressure - reading[20].pressure; /* Trend over the last 3-hours*/
ForecastToImgTxt(get_forecast_text(reading[23].pressure, trend, look_3hr));/* From forecast and trend determine what image to display*/
weather_description wx_text = get_forecast_text(read_pressure(), trend, look_1hr);
reading[23].pressure = (reading[23].pressure + read_pressure())/2; /* 1hr*/
ForecastToImgTxt(wx_text);
byte sel = 1;
if (wx_text == GoodClearWeather) {image = sunny_img; current_wx = sunny; weather_text = "Good clear weather"; sel = 1;}
else if (wx_text == BecomingClearer) {image = mostlysunny_img; current_wx = mostlysunny; weather_text = "Becoming clearer";sel = 2;}
else if (wx_text == NoChange) {image = cloudy_img; current_wx = cloudy; weather_text = "No change, clearing"; sel = 3;}
else if (wx_text == ClearSpells) {image = mostlysunny_img; current_wx = mostlysunny; weather_text = "Clear spells"; sel = 2;}
else if (wx_text == ClearingWithin12hrs) {image = mostlysunny_img; current_wx = mostlysunny; weather_text = "Clearing within 12-hrs";sel = 2;}
else if (wx_text == ClearingAndColder) {image = mostlysunny_img; current_wx = mostlysunny; weather_text = "Clearing and colder";sel = 2;}
else if (wx_text == GettingWarmer) {image = mostlysunny_img; current_wx = mostlysunny; weather_text = "Getting warmer";sel = 2;}
else if (wx_text == WarmerIn2daysRainLikely) {image = rain_img; current_wx = rain; weather_text = "Warmer in 2-days, rain likely";sel = 4;}
else if (wx_text == ExpectRain) {image = rain_img; current_wx = rain; weather_text = "Expect rain";sel = 2;}
else if (wx_text == WarmerRainWithin36hrs) {image = rain_img; current_wx = rain; weather_text = "Warmer, rain within 36-hrs";sel = 4;}
else if (wx_text == RainIn18hrs) {image = rain_img; current_wx = rain; weather_text = "Rain in 18-hrs";sel = 4;}
else if (wx_text == RainHighWindsClearAndCool) {image = rain_img; current_wx = rain; weather_text = "Rain, high winds, clear and cool";sel = 4;}
else if (wx_text == GalesHeavyRainSnowInWinter) {image = tstorms_img; current_wx = tstorms; weather_text = "Gales, heavy rain, in winter snow";sel = 5;}
/* Select Icon */
switch (sel) {
case 1: /* Soleil*/
u8g.setFont(u8g_font_04b_03);
u8g.setPrintPos(25,51);
if(frame==0)
u8g.drawXBMP(57, 25,u8g_logo_width, u8g_logo_height, u8g_Sun_1_bits );
else if (frame == 1)
u8g.drawXBMP(57, 25,u8g_logo_width, u8g_logo_height,u8g_Sun_2_bits );
break;
case 2: /* Ensoleillee*/
u8g.setFont(u8g_font_04b_03);
u8g.setPrintPos(25,51);
u8g.drawXBMP( 57, 25,u8g_logo_width, u8g_logo_height, u8g_ensoleillee_bits);
break;
case 3:/* Nuageux*/
u8g.setFont(u8g_font_04b_03);
u8g.setPrintPos(25,51);
u8g.drawXBMP( 57, 25,u8g_logo_width, u8g_logo_height, u8g_nuageux_bits);
break;
case 4:/* Pluie*/
u8g.setFont(u8g_font_04b_03);
u8g.setPrintPos(25,51);
u8g.drawXBMP( 57, 25,u8g_logo_width, u8g_logo_height, u8g_pluie_bits);
break;
case 5:/* Tempete*/
u8g.setFont(u8g_font_04b_03);
u8g.setPrintPos(25,51);
u8g.drawXBMP( 57, 25,u8g_logo_width, u8g_logo_height, u8g_orageux_bits);
} // .end Switch Select
}
void turntable() {
DateTime now = RTC.now();
// center /
int x2=128/2;
int y2=64/2;
// radius /
int r2=22;
// angle/
u8g.setFont(u8g_font_6x10);
u8g.setPrintPos(1,50);
u8g.print("degre");//turntable
u8g.setPrintPos(2,60);
u8g.print(degre);//turntable
u8g.setPrintPos(99,50);
u8g.print("steps");
u8g.setPrintPos(103,60);
u8g.print(stepper);
// affichage position turntable ecran /
u8g.setFont(u8g_font_6x10);
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*degre*2*3.14/360), y2-r2*cos(1*degre*2*3.14/360));
u8g.drawCircle(x2, y2, r2);
}
void commande(){
DateTime now = RTC.now();
int dayOfTheWeek = now.dayOfTheWeek();
zis = now.dayOfTheWeek();
switch(dayOfTheWeek){
case 0:
Serial.println("Dimanche");
if( daysOfTheWeek[now.dayOfTheWeek()]&& "Dim"){
degre = 0;// visu table
degre_1 = degre/2;
EEPROM.update(22,degre_1);
}
break;
case 1:
Serial.println("Lundi");
if( daysOfTheWeek[now.dayOfTheWeek()]&& "Lun"){
degre = 60;//visu table
degre_1 = degre/2;
EEPROM.update(22,degre_1);
}
break;
case 2:
Serial.println("Mardi");
if( daysOfTheWeek[now.dayOfTheWeek()]&& "Mar"){
degre = 120;//visu table
degre_1 = degre/2;
EEPROM.update (22,degre_1);
}
break;
case 3:
Serial.println("Mercredi");
if( daysOfTheWeek[now.dayOfTheWeek()]&& "Mer"){
degre = 180;// visu table
degre_1 = degre/2;
EEPROM.update(22,degre_1);
}
break;
case 4:
Serial.println("Jeudi");
if( daysOfTheWeek[now.dayOfTheWeek()]&& "Jeu"){
degre = 240;// visu table
degre_1 = degre/2;
EEPROM.update(22,degre_1);
}
break;
case 5:
Serial.println("Vendredi");
if( daysOfTheWeek[now.dayOfTheWeek()]&& "Ven"){
degre = 300;//visu table
degre_1= degre/2;
EEPROM.update(22,degre_1);
}
break;
case 6:
Serial.println("Samedi");
if( daysOfTheWeek[now.dayOfTheWeek()]&& "Sam"){
degre = 360;//visu table
degre_1= degre/2;
EEPROM.update(22,degre_1);
}
}
moteur();//moteur nema 17
}
void moteur(){// stepper nema 17
DateTime now = RTC.now();
zis = now.dayOfTheWeek();
int n;
float stepPerDegre = 0.45; //ajustement pour la couronne dentelée // full step nema = 1.8
stepper = degre/stepPerDegre;//nbr de steps
degre_1 = (EEPROM.read(22));
degre = degre_1*2;
currentDegre_1 = (EEPROM.read(23));
currentDegre = currentDegre_1*2;// EEPROM maxi 255,currentAngle *2;
if( currentDegre != degre ){
if( currentDegre < degre){
digitalWrite(dirPin,HIGH);
digitalWrite(enPin,LOW);
n = degre - currentDegre;
numstep = n / stepPerDegre;
}
else if( currentDegre > degre){
digitalWrite(dirPin,LOW);
digitalWrite(enPin,LOW);
n = currentDegre - degre;
if( degre == 0){
n = currentDegre;
}
numstep = n / stepPerDegre;
}
for(int x = 0; x < numstep; x++) {
digitalWrite(stepPin,HIGH);
delayMicroseconds(800);//1000
digitalWrite(stepPin,LOW);
delayMicroseconds(800);
}
currentDegre_1 = degre_1;
EEPROM.update(23,currentDegre_1);
}
delay(500);//500
Serial.println("Deblocage axe");
digitalWrite( enPin, HIGH ); // logique inversée
}
int max_day(){
int ma_valeur_de_maxday=0;
DateTime now = RTC.now();
if (now.month() == 4 || now.month() == 6 || now.month() == 9 || now.month() == 11){ //30 jours = Avril, Juin,Septembre,Novembre.
ma_valeur_de_maxday = 30;
}
else {
ma_valeur_de_maxday = 31; //... all the others have 31
}
if (now.month() == 2 && now.year() % 4 == 0){ //... Exception Fevrier = 28 jours , ou 29 jours année bissextile.
ma_valeur_de_maxday = 29;
}
if (now.month() == 2 && now.year() % 4 != 0){
ma_valeur_de_maxday = 28;
}
return ma_valeur_de_maxday;
}
void loop(void) {
u8g.setFont(u8g_font_6x10);
DateTime now = RTC.now();
int year = now.year();
int month = now.month();
int day = now.day();
int hour = now.hour();
int minute = now.minute();
int seconde = now.second();
int riseMin=(Rise_time[0]*60)+Rise_time[1];
int setMin=(Set_time[0]*60)+Set_time[1];
TimeMins = (now.hour() * 60) + now.minute();
/* Variables */
float F_TIMEZONE = EEPROM.read(4);
float F_LATITUDE = EEPROM.read(3);
float F_LATITUDE_1 = EEPROM.read(6);
float F_LONGITUDE = EEPROM.read(2);
float F_LONGITUDE_1 = EEPROM.read(5);
float F_Long = EEPROM.read(2)+ (float)(EEPROM.read(5)/100.);
float F_Lat = EEPROM.read(3)+ (float)(EEPROM.read(6)/100.);
TIMEZONE = F_TIMEZONE;
LATITUDE = F_Lat;
LONGITUDE= F_Long;
/*Timelord initialisation*/
myLord.TimeZone(TIMEZONE * 60);
myLord.Position(LATITUDE, LONGITUDE);
/* Moon Rise initialisation */
riseset(LATITUDE, LONGITUDE, now.day(), now.month(), now.year(), TIMEZONE);
/* BME 280 */
bme.readPressure();
bme.readTemperature();
bme.readHumidity();
Moonset = Set_time[0]*60 + Set_time[1];
moonsetHour = Set_time[0];
moonsetMin = Set_time[1];
Moonrise = Rise_time[0]*60 + Rise_time[1];
moonriseHour = Rise_time[0];
moonriseMin = Rise_time[1];
TimeMins = (now.hour() * 60) + now.minute();
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(" (");
int dayOfTheWeek = now.dayOfTheWeek();
zis = now.dayOfTheWeek();
Serial.print(daysOfTheWeek[zis]);
Serial.println(") ");
u8g.setFont(u8g_font_6x10);
commande();
pushlength = pushlengthset;
pushlength = getpushlength();
delay (10);
if (pushlength < pushlengthset)
{
if((buttonstate == LOW)&&(old_buttonstate==HIGH)){/* anti rebond */
}
state = state+1 ;
if (state > 5) state = 0;
delay(10);
momentaprindere = millis();
}
old_buttonstate = val;/*old_buttonstate = buttonstate;*/
if ((millis() - momentaprindere > tpaprindere) and (state != 0))/*delay pour revenir à state 0 moment d'allumage>type d'allumage*/
{
state = 0;
}
if(state == 1){
draw1();
}
if(state == 2){
draw2();
}
if (state == 3){
draw3();
}
if (state == 4){
draw4();
}
if (state == 5){
draw5();
}
if (state == 0){
draw0();
}
/*This runs the setclock routine if the knob is pushed for a long time*/
if (pushlength > pushlengthset) {
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();
setFuseautemp = EEPROM.read(4);
setLongitudetemp = EEPROM.read(2);
setLongitudetemp_1 = EEPROM.read(5);
setLatitudetemp = EEPROM.read(3);
setLatitudetemp_1 = EEPROM.read(6);
setLatitude();
setLatitude_1();
setLongitude();
setLongitude_1();
setFuseau();
setclock();
pushlength = pushlengthset;
};
} /* end main loop*/
/* 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 draw0(void) { // écran principal
/* picture loop */
u8g.firstPage();
do {
draw();
drawMoon();// Moon affichage
} while( u8g.nextPage() );
frame ++;
if(frame>1)
frame = 0;
/* rebuild the picture after some delay */
delay(100);
}
void draw1(void) {/*écran secondaire Sun */
u8g.firstPage();
do {
drawFrame1() ;
u8g.setFont(u8g_font_6x10);
u8g.setPrintPos(2,10);
u8g.print("SunAngle");
/* affichage heure zenith*/
u8g.setFont(u8g_font_6x10);
u8g.setPrintPos(95,10 );
if(zenith_Hour<0)
u8g.print("0");
u8g.print(zenith_Hour);
u8g.print(":");
if (zenith_Min<10)
u8g.print("0");
u8g.print (zenith_Min);
/*affichage Angle*/
u8g.setPrintPos(55,62);
u8g.print(angle);//angle (EEPROM.read(13))
u8g.setPrintPos(1,20);
u8g.print(pwm2);//(EEPROM.read(20));
u8g.setPrintPos(1,30);
u8g.print(valeur_Sun);//(EEPROM.read(20));
angle = (EEPROM.read(13));
/*evite de depasser l'angle*/
if(angle < 0)
angle = 0;
else if(angle > 180)
angle = 180;
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);//
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
DateTime now = RTC.now(); //x1=57,y1=43,r_1=35,u8g_logo_width = 16,u8g_logo_height = 16,
CalcSun ();
myLord.SunRise(sunTime); // Computes Sun Rise.
myLord.SunSet(sunTime);
/* levée et couché du soleil*/
u8g.setFont(u8g_font_6x10);
u8g.setPrintPos(5,62);
if(SunriseHour<10);
u8g.print("0");
u8g.print(SunriseHour);
u8g.print (":");
if (SunriseMin <10)
u8g.print("0");
u8g.print (SunriseMin);
u8g.setPrintPos(95,62);
if(SunsetHour<10)
u8g.print("0");
u8g.print (SunsetHour);
u8g.print (":");
if (SunsetMin <10)
u8g.print("0");
u8g.print (SunsetMin);
}
while ( u8g.nextPage() );
frame ++;
if(frame>1)
frame = 0;
/* rebuild the picture after some delay */
delay(100);
}
void draw2(void){/*écran secondaire LUNE */
u8g.firstPage();
do {
u8g.setFont(u8g_font_6x10);
u8g.setPrintPos(0,10);
u8g.print("Moon");
/*pwm Lune*/
DateTime now = RTC.now();
TimeMins = (now.hour() * 60) + now.minute();
int riseMin = Rise_time[0] * 60 + Rise_time[1]; // Attention variables globales à modifier avec des fonctions...
int setMin = Set_time[0]*60 + Set_time[1]; // Attention variables globales ...
int minuitLunaire= 0 ;
int pwmLune = 0;
pwmLune = calculPwm ( TimeMins, riseMin, setMin );
// gestion du cas où le levé est plus tard que le couché pour la lune
if( riseMin > setMin)
setMin += 24 * 60; // ajout de 24h...
if( TimeMins < riseMin)
TimeMins += 24 * 60; // ajout de 24h...
//fin de gestion
minuitLunaire = (riseMin + setMin)/2 ;
u8g.setPrintPos(0,20);
u8g.print("lune: ");
u8g.print(pwmLune);
/*switch case moon*/
u8g.setPrintPos(0,30);
u8g.print(valeur_Moon);
/* affichage minuit lunaire*/
u8g.setPrintPos(95,10 );
if(lunaire_Hour<0)
u8g.print("0");
u8g.print(lunaire_Hour);
u8g.print(":");
if (lunaire_Min<10)
u8g.print("0");
u8g.print (lunaire_Min);
u8g.setPrintPos(95,30);
u8g.print(minuitLunaire);
u8g.setPrintPos(5,62);
if(moonriseHour<10)
u8g.print("0");
u8g.print(moonriseHour);
u8g.print(":");
if (moonriseMin <10)
u8g.print("0");
u8g.print (moonriseMin);
u8g.setPrintPos(95,62);
if(moonsetHour<10)
u8g.print("0");
u8g.print (moonsetHour);
u8g.print (":");
if (moonsetMin <10)
u8g.print("0");
u8g.print (moonsetMin);
/*switch case phase Moon*/
int mp = moon_phase();
switch (mp){
case 0:
u8g.setFont(u8g_font_04b_03);
u8g.setPrintPos(2,28);
u8g.drawXBMP(57,25,u8g_logo_width, u8g_logo_height, u8g_pleine_LUNE_bits);
break;
case 1:
u8g.setFont(u8g_font_04b_03);
u8g.setPrintPos(2,28);
u8g.drawXBMP(57,25,u8g_logo_width, u8g_logo_height, u8g_premier_croissant_bits);
break;
case 2:
u8g.setFont(u8g_font_04b_03);
u8g.setPrintPos(2,28);
u8g.drawXBMP(57,25,u8g_logo_width, u8g_logo_height, u8g_LUNE_QUART_bits);
break;
case 3:
u8g.setFont(u8g_font_04b_03);
u8g.setPrintPos(2,28);
u8g.drawXBMP(57,25,u8g_logo_width, u8g_logo_height, u8g_lune_dernier_croissant_bits);
break;
case 4:
u8g.setFont(u8g_font_04b_03);
u8g.setPrintPos(2,28);
u8g.drawXBMP(57,25,u8g_logo_width, u8g_logo_height,u8g_lune_noir_bits);
break;
case 5:
u8g.setFont(u8g_font_04b_03);
u8g.setPrintPos(2,28);
u8g.drawXBMP(57,25,u8g_logo_width, u8g_logo_height, u8g_dernier_decroissant_bits);
break;
case 6:
u8g.setFont(u8g_font_04b_03);
u8g.setPrintPos(2,28);
u8g.drawXBMP(57,25,u8g_logo_width, u8g_logo_height, u8g_quartier_decroissant_bits);
break;
case 7:
u8g.setFont(u8g_font_04b_03);
u8g.setPrintPos(2,28);
u8g.drawXBMP(57,25,u8g_logo_width, u8g_logo_height, u8g_premier_decroissant_bits);
break;
}
const char* newNfm = (const char*) nfm.c_str();
}
while (
u8g.nextPage() );
}
void draw3(void) {/*écran secondaire Turntable */
u8g.firstPage();
do {
DateTime now = RTC.now();
u8g.setFont(u8g_font_6x10);
u8g.setPrintPos(2,10);
u8g.print("Turntable");
turntable();
} while (
u8g.nextPage() );
}
void draw4(void) {/*écran secondaire Arrosage*/
u8g.firstPage();
do {
u8g.setFont(u8g_font_6x10);
u8g.setPrintPos(2,10);
u8g.print("Arrosage");
/* Computes Season */
current_season = myLord.Season(SeasonTime);
if (current_season == 0){sea=0;}
if (current_season == 1){sea=1;}
if (current_season == 2){sea=2;}
if (current_season == 3){sea=3;}
/* Select Icon saisons */
switch (sea) {
case 0: /* Hiver*/
u8g.setFont(u8g_font_6x10);
u8g.setPrintPos(2,20);
u8g.print("Hiver ");
break;
case 1: /* Printemps*/
u8g.setFont(u8g_font_6x10);
u8g.setPrintPos(2,20);
u8g.print("Printemps");
break;
case 2:/* Eté*/
u8g.setFont(u8g_font_6x10);
u8g.setPrintPos(2,20);
u8g.print("Ete ");
break;
case 3:/* Automne*/
u8g.setFont(u8g_font_6x10);
u8g.setPrintPos(2,20);
u8g.print("Automne ");
} // .end Switch Select
}
while (
u8g.nextPage() );
}
void draw5(void) {/*écran secondaire Reglages*/
u8g.firstPage();
do {
u8g.setFont(u8g_font_6x10);
u8g.setPrintPos(2,10);
u8g.print("Reglages");
/*Affichage Timezone*/
u8g.setFont(u8g_font_6x10);
u8g.setPrintPos(2,20);
u8g.print("utc:");
/*Reglage Timezone*/
u8g.setFont(u8g_font_6x10);
u8g.setPrintPos( 30,20 );
u8g.print(EEPROM.read(4));
/*Affichage Longitude*/
u8g.setFont(u8g_font_6x10);
u8g.setPrintPos(2,30);
u8g.print("lon:");
/*Reglage Longitude*/
u8g.setFont(u8g_font_6x10);
u8g.setPrintPos(30,30 );
float F_Long = (EEPROM.read(2))+ (float)(EEPROM.read(5)/100.);
u8g.print((float)F_Long);
/*Affichage Latitude*/
u8g.setFont(u8g_font_6x10);
u8g.setPrintPos(2,40);
u8g.print("lat:");
/*Reglage Latitude*/
u8g.setFont(u8g_font_6x10);
u8g.setPrintPos(30,40 );
float F_Lat = (EEPROM.read(3))+ (float)(EEPROM.read(6)/100.);
u8g.print((float)F_Lat);
}
while (
u8g.nextPage() );
}
int setFuseau() {
pushlength = pushlengthset;
pushlength = getpushlength ();
if (pushlength != pushlengthset) {
return setFuseautemp;
}
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);
}
setFuseautemp = setFuseautemp + knobval;
if (setFuseautemp < 1) {/*0*/
setFuseautemp = 0;
}
if (setFuseautemp > 2) {/*3*/
setFuseautemp = 3;
}
itoa(setFuseautemp, tmp_string, 10);
EEPROM.update(4,setFuseautemp);
u8g.firstPage();
do {
u8g.setFont(u8g_font_6x10);
u8g.drawStr( 0, 20, "Set Timezone");
u8g.drawStr(35, 40, tmp_string);
} while ( u8g.nextPage() );
setFuseau();
}
int setLongitude() {
pushlength = pushlengthset;
pushlength = getpushlength ();
if (pushlength != pushlengthset) {
return setLongitudetemp;
}
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);
}
setLongitudetemp = setLongitudetemp + knobval;
if (setLongitudetemp < 1) {/*0*/
setLongitudetemp = 0;
}
if (setLongitudetemp > 99) {/*100*/
setLongitudetemp = 100;
}
itoa(setLongitudetemp, tmp_string, 10);
EEPROM.update(2,setLongitudetemp);
u8g.firstPage();
do {
u8g.setFont(u8g_font_6x10);
u8g.drawStr( 0, 20, "Set Longitude Degres");
u8g.drawStr(35, 40, tmp_string);
} while ( u8g.nextPage() );
setLongitude();
}
int setLongitude_1() {
pushlength = pushlengthset;
pushlength = getpushlength ();
if (pushlength != pushlengthset) {
return setLongitudetemp_1;
}
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);
}
setLongitudetemp_1 = setLongitudetemp_1 + knobval;
if (setLongitudetemp_1 < 1) {/*0*/
setLongitudetemp_1 = 0;
}
if (setLongitudetemp_1 > 99) {/*100*/
setLongitudetemp_1 = 100;
}
itoa(setLongitudetemp, tmp_string, 10);
itoa(setLongitudetemp_1, tmp_string, 10);
EEPROM.update(2,setLongitudetemp);
EEPROM.update(5,setLongitudetemp_1);
u8g.firstPage();
do {
u8g.setFont(u8g_font_6x10);
u8g.drawStr( 0, 20, "Set Longitude Mins");
u8g.drawStr(35, 40, tmp_string);
} while ( u8g.nextPage() );
setLongitude_1();
}
int setLatitude() {
pushlength = pushlengthset;
pushlength = getpushlength ();
if (pushlength != pushlengthset) {
return setLatitudetemp;
}
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);
}
setLatitudetemp = setLatitudetemp + knobval;
if (setLatitudetemp < 1) {/*0*/
setLatitudetemp = 0;
}
if (setLatitudetemp > 99) {/*100*/
setLatitudetemp = 100;
}
itoa(setLatitudetemp, tmp_string, 10);
EEPROM.update(3,setLatitudetemp);
u8g.firstPage();
do {
u8g.setFont(u8g_font_6x10);
u8g.drawStr( 0, 20, "Set Latitude Degres");
u8g.drawStr(35, 40, tmp_string);
} while ( u8g.nextPage() );
setLatitude();
}
int setLatitude_1() {
pushlength = pushlengthset;
pushlength = getpushlength ();
if (pushlength != pushlengthset) {
return setLatitudetemp_1;
}
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);
}
setLatitudetemp_1 = setLatitudetemp_1 + knobval;
if (setLatitudetemp_1 < 1) {/*0*/
setLatitudetemp_1 = 0;
}
if (setLatitudetemp_1 > 99) {/*100*/
setLatitudetemp_1 = 100;
}
itoa(setLatitudetemp, tmp_string, 10);
itoa(setLatitudetemp_1, tmp_string, 10);
EEPROM.update(3,setLatitudetemp);
EEPROM.update(6,setLatitudetemp_1);
u8g.firstPage();
do {
u8g.setFont(u8g_font_6x10);
u8g.drawStr( 0, 20, "Set Latitude Mins");
u8g.drawStr(35, 40, tmp_string);
} while ( u8g.nextPage() );
setLatitude_1();
}
void draw_Bonsai(void){
/* picture loop*/
u8g.firstPage();
do {
u8g.drawBitmapP(0, 0, 16, 64, bonsai_bitmap);
} while ( u8g.nextPage() );
/* rebuild the picture after some delay*/
delay(100);
}
//sets the clock
void setclock (){
/*Timelord initialisation*/
myLord.TimeZone(TIMEZONE * 60);
myLord.Position(LATITUDE, LONGITUDE);
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];
}
/* 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, tmp_string, 10);
u8g.firstPage();
do {
u8g.setFont(u8g_font_6x10);
u8g.drawStr( 0, 20, "Set Annee");
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.setFont(u8g_font_6x10);
u8g.drawStr( 0, 20, "Set Mois");
u8g.drawStr(25, 40, tmp_string);
} while( u8g.nextPage() );
setmonth();
}
int setday () {
if (setmonthtemp == 4 || setmonthtemp == 6 || 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.setFont(u8g_font_6x10);
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.setFont(u8g_font_6x10);
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.setFont(u8g_font_6x10);
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.setFont(u8g_font_6x10);
u8g.drawStr( 0, 20, "Set Minutes");
u8g.drawStr(25, 40, tmp_string);
} while( u8g.nextPage() );
setmins();
}