//--------------------------------------------
const int pResistor = A0;
const int ledStrip = 10;
//--------------------------------------------
int foto;
int led;
int ledBrightness = 0;
bool brightnessUp = false;
bool goingNight = true;
//long nextSwitchTime = millis()+1;
//--------------------------------------------
//DEBUG
bool DEBUG = true;
//--------------------------------------------


void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(pResistor, INPUT);
  pinMode(ledStrip, OUTPUT);

}

void loop() {
  // put your main code here, to run repeatedly:
  int foto = analogRead(pResistor);
  //analogWrite(ledStrip, led); // can be value between 0 and 255 (led)

  //led = 255;


  if (foto > 750)
  {
    goingNight = true;
  }

  if(foto < 60 && goingNight == true)
  {
  brightnessUp = true;
  goingNight = false;
  }
  

  while (brightnessUp == true)
  {
    ledBrightness = 255;
    analogWrite(ledStrip, ledBrightness);
    Serial.print("LED Brightness: ");
    Serial.println(ledBrightness);
    delay(10800000);

    ledBrightness -= 17;
    analogWrite(ledStrip, ledBrightness);
    Serial.print("LED Brightness: ");
    Serial.println(ledBrightness);
    delay(120000);
    ledBrightness -= 17;
    analogWrite(ledStrip, ledBrightness);
    Serial.print("LED Brightness: ");
    Serial.println(ledBrightness);
    delay(120000);
    ledBrightness -= 17;
    analogWrite(ledStrip, ledBrightness);
    Serial.print("LED Brightness: ");
    Serial.println(ledBrightness);
    delay(120000);
    ledBrightness -= 17;
    analogWrite(ledStrip, ledBrightness);
    Serial.print("LED Brightness: ");
    Serial.println(ledBrightness);
    delay(120000);
    ledBrightness -= 17;
    analogWrite(ledStrip, ledBrightness);
    Serial.print("LED Brightness: ");
    Serial.println(ledBrightness);
    delay(120000);

    ledBrightness -= 17;
    analogWrite(ledStrip, ledBrightness);
    Serial.print("LED Brightness: ");
    Serial.println(ledBrightness);
    delay(120000);
    ledBrightness -= 17;
    analogWrite(ledStrip, ledBrightness);
    Serial.print("LED Brightness: ");
    Serial.println(ledBrightness);
    delay(120000);
    ledBrightness -= 17;
    analogWrite(ledStrip, ledBrightness);
    Serial.print("LED Brightness: ");
    Serial.println(ledBrightness);
    delay(120000);
    ledBrightness -= 17;
    analogWrite(ledStrip, ledBrightness);
    Serial.print("LED Brightness: ");
    Serial.println(ledBrightness);
    delay(120000);
    ledBrightness -= 17;
    analogWrite(ledStrip, ledBrightness);
    Serial.print("LED Brightness: ");
    Serial.println(ledBrightness);
    delay(120000);

    ledBrightness -= 17;
    analogWrite(ledStrip, ledBrightness);
    Serial.print("LED Brightness: ");
    Serial.println(ledBrightness);
    delay(120000);
    ledBrightness -= 17;
    analogWrite(ledStrip, ledBrightness);
    Serial.print("LED Brightness: ");
    Serial.println(ledBrightness);
    delay(120000);
    ledBrightness -= 17;
    analogWrite(ledStrip, ledBrightness);
    Serial.print("LED Brightness: ");
    Serial.println(ledBrightness);
    delay(120000);
    ledBrightness -= 17;
    analogWrite(ledStrip, ledBrightness);
    Serial.print("LED Brightness: ");
    Serial.println(ledBrightness);
    delay(120000);
    ledBrightness -= 17;
    analogWrite(ledStrip, ledBrightness);
    Serial.print("LED Brightness: ");
    Serial.println(ledBrightness);
    delay(120000);

    ledBrightness = 0;
    analogWrite(ledStrip, ledBrightness);
    brightnessUp = false;
    Serial.print("LED Brightness: ");
    Serial.println(ledBrightness);


    Serial.println("brightnessUp END");
  }
  
  
  

  //Serial.println(nextSwitchTime);


  analogWrite(ledStrip, ledBrightness); // can be value between 0 and 255 (led)
  if (DEBUG == true)
  {
    //DEBUG
    //Serial.print("pResistor: ");
    //Serial.println(pResistor);
    Serial.print("foto: ");
    Serial.println(foto);
    //Serial.print("led: ");
    //Serial.println(led);
    Serial.print("ledBrightness: ");
    Serial.println(ledBrightness);
    //Serial.print("ledStrip: ");
    //Serial.println(ledStrip);
    Serial.print("Night?: ");
    Serial.println(goingNight);
  }
  delay(2500);
}