// Horloge pixel V1.0 Janv 2024 JPRO
// Librairie
 #include "Adafruit_NeoPixel.h"
 #define PIN  2
 #define NUMPIXELS 110
 Adafruit_NeoPixel strip (NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
 #include "RTClib.h"
 RTC_DS1307 rtc;

// Variable bp
 int etat_bp_8;
 int etat_bp_9;
 int etat_bp_10;
 int etat_bp_11;
 //int Color1 = 0 , Color2 = 0 , Color3 = 225 ; // BLEU
 int Color1 = 255 , Color2 = 0 , Color3 = 0 ; // ROUGE

void setup() {
   Serial.begin(115200);
   if (! rtc.begin()) {
   Serial.println("Couldn't find RTC");
   Serial.flush();
   abort();   }

  pinMode(8,INPUT_PULLUP);
  pinMode(9,INPUT_PULLUP);
  pinMode(10,INPUT_PULLUP);
  pinMode(11,INPUT_PULLUP);

   strip.begin();
   // Message JP RICOIS
    
    strip.setPixelColor(3, strip.Color(Color1, Color2, Color3));
    strip.setPixelColor(6, strip.Color(Color1, Color2, Color3));
    strip.setPixelColor(61, strip.Color(Color1, Color2, Color3));
    strip.setPixelColor(71, strip.Color(Color1, Color2, Color3));
    strip.setPixelColor(79, strip.Color(Color1, Color2, Color3));
    strip.setPixelColor(85, strip.Color(Color1, Color2, Color3));
    strip.setPixelColor(98, strip.Color(Color1, Color2, Color3));
    strip.setPixelColor(104, strip.Color(Color1, Color2, Color3));
    strip.show(); 
    delay(500);
    strip.clear();//strip.show(); 
    strip.show();delay(1);

}

int mem1  ; int Minutes ;

void loop() {

bool etat_bp_8  = digitalRead(8);
bool etat_bp_9  = digitalRead(9);
bool etat_bp_10 = digitalRead(10);
bool etat_bp_11 = digitalRead(11);


Serial.print(" / bp11 : ");
   Serial.print(etat_bp_11);
   Serial.print(" / bp10 : ");
   Serial.print(etat_bp_10);
   Serial.print(" / bp9 : ");
   Serial.print(etat_bp_9);
   Serial.print(" / bp8 : ");
   Serial.print(etat_bp_8);
   Serial.print(" Mem ");
   Serial.print(mem1);
   Serial.println();
   
DateTime now = rtc.now() ;

 //DateTime now = RTC.now();

     /*        // Functions to move the cursor to first line fisrt position
    Serial.print("Date ");
    if(now.month() < 10){           // Zero padding if value less than 10 ie."09" instead of "9"
      Serial.print("0");
      Serial.print(now.month(), DEC);
    }
    Serial.print('/');
    if(now.day() < 10){            // Zero padding if value less than 10 ie."09" instead of "9"
      Serial.print("0");
      Serial.print(now.day(), DEC);
    }
    Serial.print('/');
    Serial.print(now.year(), DEC);*/
/*************  Now comes the time section  **************/
    const uint8_t h = now.hour();
    const uint8_t hr_12 = h%12;
    int Heures ; int Heures2 ;
    if ( mem1 == 0 ) { 
     Minutes =  now.minute() ;  }

    //LCD.cursorTo(2,1);              // Functions to move the cursor to second line fisrt position
    Serial.print(" Time ");
    if(hr_12 < 10){                // Zero padding if value less than 10 ie."09" instead of "9"
      Serial.print(" ");
      Serial.print((h > 12) ? h - 12 : ((h == 0) ? 12 : h), DEC); // Conversion to AM/PM  
      }
    else{
      Serial.print((h > 12) ? h - 12 : ((h == 0) ? 12 : h), DEC); // Conversion to AM/PM
      }
    Serial.print(':');
    /*if(now.minute() < 10){         // Zero padding if value less than 10 ie."09" instead of "9"
      Serial.print("0");
      Serial.print(now.minute(), DEC);    }
    else{
       Serial.print(now.minute(), DEC);    }
    Serial.print(':');
    if(now.second() < 10){        // Zero padding if value less than 10 ie."09" instead of "9"
      Serial.print("0");
      Serial.print(now.second(), DEC);    }
    else{
       Serial.print(now.second(), DEC);    }*/
    if(h < 12){                  // Adding the AM/PM sufffix
      Serial.print(" AM ");
      Heures2 = now.hour() ;    }
    else{
      Serial.print(" PM ");
      Heures2 = now.hour() -12 ;    }
      Serial.print(Heures2);Serial.print(" ");

//       ******* REGLEGE *******
  //int Heures ;// , Heures_adj  , Minutes_adj   ;
  //*

if ( etat_bp_11 == 0 ) { 
    Serial.println( "Reglage");
    strip.clear();//strip.show(); 
    strip.show();
    mem1 = 1 ;
    strip.setPixelColor( 1, strip.Color(Color1, Color2, Color3));
    strip.setPixelColor(99, strip.Color(Color1, Color2, Color3));
    strip.show();
    Serial.print(" Mem= ");
    Serial.print(mem1);
    Serial.println();
    delay (500) ; }


if ( mem1 == 1 ) { 
    Serial.print( " Reglage en cours ");
    int Minutes_adj = 0 , Heures_adj = 0 , x , y ;
    int Jour_adj = 0 , Mois_adj = 0 , Annee_adj = 0 ;
    strip.setPixelColor(99, strip.Color(Color1, Color2, Color3));
    strip.show();
    delay (50) ;

   if ( etat_bp_10 == 0 ) {
   Minutes = Minutes + 1 ; Serial.println(Minutes) ;
   delay (20) ;    }

   if ( etat_bp_9 == 0 ) {
   y = y+1 ; Serial.println(x);
   strip.clear();
   strip.setPixelColor(y, strip.Color(Color1, Color2, Color3));
   strip.show();
   delay (250) ;    }

   if ( etat_bp_8 == 0 ) {   Serial.println( "Sortie");   
     mem1 = 0 ;
   }
}
   
//*/

  
// HEURE
  if (  Minutes >= 35 )  {  Heures = Heures2 +1 ; }
  else {  Heures = Heures2 ; }
  Serial.print("Current time: ");
  Serial.print(now.hour(), DEC);  Serial.print(":");
  Serial.print(now.minute(), DEC);  Serial.print(":");
  Serial.print(now.second(), DEC);  
  Serial.println();
 // LUMINOSITE  
  
  strip.setBrightness(255);  // luminosité de la LED (maximum 255)
  strip.clear();//strip.show(); 
  strip.show();//
  
  // IL EST
   if ( now.minute() == 00 || now.minute() == 15 || now.minute() == 30 || now.minute() == 45 )
   {   // affiche_il_est(); 
   strip.setPixelColor(0, strip.Color(Color1, Color2, Color3));
   strip.setPixelColor(1, strip.Color(Color1, Color2, Color3));
   strip.setPixelColor(3, strip.Color(Color1, Color2, Color3));
   strip.setPixelColor(4, strip.Color(Color1, Color2, Color3));
   strip.setPixelColor(5, strip.Color(Color1, Color2, Color3));
   strip.show(); 
  }
  // Mot heure ou heureS 
   if (  Heures != 12  &&  Heures != 0 )    {
   strip.setPixelColor(56, strip.Color(Color1, Color2, Color3));
   strip.setPixelColor(57, strip.Color(Color1, Color2, Color3));
   strip.setPixelColor(58, strip.Color(Color1, Color2, Color3));
   strip.setPixelColor(59, strip.Color(Color1, Color2, Color3));
   strip.setPixelColor(60, strip.Color(Color1, Color2, Color3));
   if ( Heures >= 1  &&  Heures != 12 && Heures != 0 )
   {  strip.setPixelColor(55, strip.Color(Color1, Color2, Color3)); }
   strip.show(); 
  }
//HEURES:
//HEURES:
  
 
switch (Heures) {
  case 1:
    strip.setPixelColor(26, strip.Color(Color1, Color2, Color3));
    strip.setPixelColor(27, strip.Color(Color1, Color2, Color3));
    strip.setPixelColor(28, strip.Color(Color1, Color2, Color3));
    strip.show();
    break;
  case 2:
    strip.setPixelColor(7 , strip.Color(Color1, Color2, Color3));
    strip.setPixelColor(8 , strip.Color(Color1, Color2, Color3));
    strip.setPixelColor(9 , strip.Color(Color1, Color2, Color3));
    strip.setPixelColor(10, strip.Color(Color1, Color2, Color3));
    strip.show();
    break;
  case 3:
    strip.setPixelColor(11, strip.Color(Color1, Color2, Color3));
    strip.setPixelColor(12, strip.Color(Color1, Color2, Color3));
    strip.setPixelColor(13, strip.Color(Color1, Color2, Color3));
    strip.setPixelColor(14, strip.Color(Color1, Color2, Color3));
    strip.setPixelColor(15, strip.Color(Color1, Color2, Color3));
    strip.show();
    break;
  case 4:
    strip.setPixelColor(21, strip.Color(Color1, Color2, Color3));
    strip.setPixelColor(20, strip.Color(Color1, Color2, Color3));
    strip.setPixelColor(19, strip.Color(Color1, Color2, Color3));
    strip.setPixelColor(18, strip.Color(Color1, Color2, Color3));
    strip.setPixelColor(17, strip.Color(Color1, Color2, Color3));
    strip.setPixelColor(16, strip.Color(Color1, Color2, Color3));
    strip.show();
    break;
  case 5:
    strip.setPixelColor(36, strip.Color(Color1, Color2, Color3));
    strip.setPixelColor(35, strip.Color(Color1, Color2, Color3));
    strip.setPixelColor(34, strip.Color(Color1, Color2, Color3));
    strip.setPixelColor(33, strip.Color(Color1, Color2, Color3));
    strip.show();
    break;
  case 6:
    strip.setPixelColor(37, strip.Color(Color1, Color2, Color3));
    strip.setPixelColor(38, strip.Color(Color1, Color2, Color3));
    strip.setPixelColor(39, strip.Color(Color1, Color2, Color3));
    strip.show();
    break;
  case 7:
    strip.setPixelColor(29, strip.Color(Color1, Color2, Color3));
    strip.setPixelColor(30, strip.Color(Color1, Color2, Color3));
    strip.setPixelColor(31, strip.Color(Color1, Color2, Color3));
    strip.setPixelColor(32, strip.Color(Color1, Color2, Color3));
    strip.show();
    break;
  case 8:
    strip.setPixelColor(43, strip.Color(Color1, Color2, Color3));
    strip.setPixelColor(42, strip.Color(Color1, Color2, Color3));
    strip.setPixelColor(41, strip.Color(Color1, Color2, Color3));
    strip.setPixelColor(40, strip.Color(Color1, Color2, Color3));
    strip.show();
    break;
  case 9:
    strip.setPixelColor(22, strip.Color(Color1, Color2, Color3));
    strip.setPixelColor(23, strip.Color(Color1, Color2, Color3));
    strip.setPixelColor(24, strip.Color(Color1, Color2, Color3));
    strip.setPixelColor(25, strip.Color(Color1, Color2, Color3));
    strip.show();
    break;
  case 10:
    strip.setPixelColor(46, strip.Color(Color1, Color2, Color3));
    strip.setPixelColor(47, strip.Color(Color1, Color2, Color3));
    strip.setPixelColor(48, strip.Color(Color1, Color2, Color3));
    strip.show();
    break;
  case 11:
    strip.setPixelColor(65, strip.Color(Color1, Color2, Color3));
    strip.setPixelColor(64, strip.Color(Color1, Color2, Color3));
    strip.setPixelColor(63, strip.Color(Color1, Color2, Color3));
    strip.setPixelColor(62, strip.Color(Color1, Color2, Color3));
    strip.show();
    break;
  default:
    Serial.println("Switch heures");
    // if nothing else matches, do the default
    // default is optional
    break;

}
  
//*///// prefixe ////////////////////////////////////////
//PREFIXE:
  if ( now.minute() >= 15  && now.minute() <= 19  )   {  
   //et
   strip.setPixelColor(86, strip.Color(Color1, Color2, Color3));
   strip.setPixelColor(87, strip.Color(Color1, Color2, Color3));
   strip.show();
   //  goto P_ET       ; 
   }
  if ( now.minute() >= 35  && now.minute() <= 44  
   ||   now.minute() >= 50  && now.minute() <= 59  )   { 
   strip.setPixelColor(66, strip.Color(Color1, Color2, Color3));
   strip.setPixelColor(67, strip.Color(Color1, Color2, Color3));
   strip.setPixelColor(68, strip.Color(Color1, Color2, Color3));
   strip.setPixelColor(69, strip.Color(Color1, Color2, Color3));
   strip.setPixelColor(70, strip.Color(Color1, Color2, Color3));
   strip.show();
   //    goto P_MOINS    ; 
   }
  if ( now.minute() >= 45  && now.minute() <= 49  )   {   
   //moins
   strip.setPixelColor(66, strip.Color(Color1, Color2, Color3));
   strip.setPixelColor(67, strip.Color(Color1, Color2, Color3));
   strip.setPixelColor(68, strip.Color(Color1, Color2, Color3));
   strip.setPixelColor(69, strip.Color(Color1, Color2, Color3));
   strip.setPixelColor(70, strip.Color(Color1, Color2, Color3));
   //LE
   strip.setPixelColor(72, strip.Color(Color1, Color2, Color3));
   strip.setPixelColor(73, strip.Color(Color1, Color2, Color3));
   strip.show();
   // goto P_M_LE     ;
   }
  //if ( now.minute() >= 35  && now.minute() <= 39  )  
  //{    strip.setPixelColor(93, strip.Color(Color1, Color2, Color3));     }
  
//MINUTES:
  if ( Minutes >= 5   && Minutes <= 9   
   ||   Minutes >= 55  && Minutes <= 59  )  
   { 
   strip.setPixelColor(94, strip.Color(Color1, Color2, Color3));
   strip.setPixelColor(95, strip.Color(Color1, Color2, Color3));
   strip.setPixelColor(96, strip.Color(Color1, Color2, Color3));
   strip.setPixelColor(97, strip.Color(Color1, Color2, Color3));
   strip.show();
   //goto M_CINQ       ; 
   }
  if ( Minutes >= 10  && Minutes <= 14  
   ||   Minutes >= 50  && Minutes <= 54  )  
   {  
   strip.setPixelColor(74, strip.Color(Color1, Color2, Color3));
   strip.setPixelColor(75, strip.Color(Color1, Color2, Color3));
   strip.setPixelColor(76, strip.Color(Color1, Color2, Color3));
   strip.show();
   //  goto M_DIX        ; 
   }
  if ( Minutes >= 15  && Minutes <= 19      
   ||   Minutes >= 45  && Minutes <= 49  )  
   {  
   strip.setPixelColor(84, strip.Color(Color1, Color2, Color3));
   strip.setPixelColor(83, strip.Color(Color1, Color2, Color3));
   strip.setPixelColor(82, strip.Color(Color1, Color2, Color3));
   strip.setPixelColor(81, strip.Color(Color1, Color2, Color3));
   strip.setPixelColor(80, strip.Color(Color1, Color2, Color3));
   strip.show();
   // goto M_QUART      ;
   } 
  if ( Minutes >= 20  && Minutes <= 29 
   ||   Minutes >= 40  && Minutes <= 44  )   {  
   strip.setPixelColor(88, strip.Color(Color1, Color2, Color3));
   strip.setPixelColor(89, strip.Color(Color1, Color2, Color3));
   strip.setPixelColor(90, strip.Color(Color1, Color2, Color3));
   strip.setPixelColor(91, strip.Color(Color1, Color2, Color3));
   strip.setPixelColor(92, strip.Color(Color1, Color2, Color3));
   strip.show();
   // goto M_VINGT      ; 
   } 
  if ( Minutes >= 25  && Minutes <= 29
   ||   Minutes >= 35  && Minutes <= 39  )   { 
   //5
   strip.setPixelColor(94, strip.Color(Color1, Color2, Color3));
   strip.setPixelColor(95, strip.Color(Color1, Color2, Color3));
   strip.setPixelColor(96, strip.Color(Color1, Color2, Color3));
   strip.setPixelColor(97, strip.Color(Color1, Color2, Color3));
   //
   strip.setPixelColor(93, strip.Color(Color1, Color2, Color3));
   //20
   strip.setPixelColor(88, strip.Color(Color1, Color2, Color3));
   strip.setPixelColor(89, strip.Color(Color1, Color2, Color3));
   strip.setPixelColor(90, strip.Color(Color1, Color2, Color3));
   strip.setPixelColor(91, strip.Color(Color1, Color2, Color3));
   strip.setPixelColor(92, strip.Color(Color1, Color2, Color3));
   strip.show();
   //  goto M_V_CINQ ; 
   } 
  if ( Minutes >= 30  && Minutes <= 34  )   {  
   //et
   strip.setPixelColor(86, strip.Color(Color1, Color2, Color3));
   strip.setPixelColor(87, strip.Color(Color1, Color2, Color3));
   //demie
   strip.setPixelColor(109, strip.Color(Color1, Color2, Color3));
   strip.setPixelColor(108, strip.Color(Color1, Color2, Color3));
   strip.setPixelColor(107, strip.Color(Color1, Color2, Color3));
   strip.setPixelColor(106, strip.Color(Color1, Color2, Color3));
   strip.setPixelColor(105, strip.Color(Color1, Color2, Color3));
   strip.show();
   //  goto M_ET_DEMIE   ; 
   } 
 //

//
//1 A 4 MINUTES
//QUATRE_MINUTE:
   if ( Minutes == 1 || Minutes == 6 || Minutes == 11 || Minutes == 16
   ||   Minutes == 21 || Minutes == 26 || Minutes == 31 || Minutes == 36
   ||   Minutes == 41 || Minutes == 46 || Minutes == 51 || Minutes == 56 )
   {    strip.setPixelColor(103, strip.Color(255, 0, 255));    }
   if ( Minutes == 2 || Minutes == 7 || Minutes == 12 || Minutes == 17
   ||   Minutes == 22 || Minutes == 27 || Minutes == 32 || Minutes == 37
   ||   Minutes == 42 || Minutes == 47 || Minutes == 52 || Minutes == 57 )
   {    strip.setPixelColor(103, strip.Color(255, 0, 255));
        strip.setPixelColor(102, strip.Color(255, 0, 255));    }
   if ( Minutes == 3 || Minutes == 8 || Minutes == 13 || Minutes == 18
   ||   Minutes == 23 || Minutes == 28 || Minutes == 33 || Minutes == 38
   ||   Minutes == 43 || Minutes == 48 || Minutes == 53 || Minutes == 58 )
   {    strip.setPixelColor(103, strip.Color(255, 0, 255));
        strip.setPixelColor(102, strip.Color(255, 0, 255)); 
        strip.setPixelColor(101, strip.Color(255, 0, 255));    }
   if ( Minutes == 4 || Minutes == 9 || Minutes == 14 || Minutes == 19
   ||   Minutes == 24 || Minutes == 29 || Minutes == 34 || Minutes == 39
   ||   Minutes == 44 || Minutes == 49 || Minutes == 54 || Minutes == 59 )
   {    strip.setPixelColor(103, strip.Color(255, 0, 255));
        strip.setPixelColor(102, strip.Color(255, 0, 255)); 
        strip.setPixelColor(101, strip.Color(255, 0, 255));  
        strip.setPixelColor(100, strip.Color(255, 0, 255));    }
   strip.show();
   
// REGLAGE

 delay(150);

}
GND5VSDASCLSQWRTCDS1307+