#include <Tlc5940.h>

const int downButtonPin = 8;     // the number of the pushbutton pin
const int upButtonPin = 7;     // the number of the pushbutton pin
int downButtonState = 0;         // variable for reading the pushbutton status
int upButtonState = 0;         // variable for reading the pushbutton status
int ledCount = 17; //liczba aktywnych wyjść (taśm led)
int brightness = 4095; //maksymalna jasność 
int brightStep = 12; //krok przy rozjaśnianiu
int delayTime = 1;
int outs[] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,17,18,19}; //wyjścia do których podpinane są taśmy

void setup()
{
  Tlc.init();
  pinMode(downButtonPin, INPUT);
  digitalWrite(downButtonPin, HIGH);  
  pinMode(upButtonPin, INPUT);     
  digitalWrite(upButtonPin, HIGH);  

 for (byte diode = 0; diode<ledCount;diode++) {
     Tlc.set(outs[diode], brightness);

 }
 Tlc.update();
  
}

void loop()
{
downButtonState = digitalRead(downButtonPin);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:

 if (downButtonState == LOW) {     
    downButton();
  //  upButton();
  } 

  upButtonState = digitalRead(upButtonPin);
  if (upButtonState == LOW) {     
    upButton();
  } 
}

void downButton() {

 for (int diode = 0; diode<ledCount;diode++) {
   
   int bright = brightness;
   do {
      if (bright<0) {
        bright = 0;
      }
      Tlc.set(outs[diode], bright);
      Tlc.update();

      delay(delayTime);
      bright = bright - brightStep;
   } while (bright>=0);
  }
  
  for (int diode = 0; diode<ledCount;diode++) {
    int bright = 0;
    while (bright<brightness) {
      bright = bright + brightStep;
      if (bright>brightness) {
        bright = brightness;
      }

      Tlc.set(outs[diode], bright);
      Tlc.update();
      delay(delayTime);
    } ;
  }

}

void upButton() {

for (int diode = ledCount-1; diode>=0;diode--) {
   
   int bright = brightness;
   do {
      if (bright<0) {
        bright = 0;
      }
      Tlc.set(outs[diode], bright);
      Tlc.update();

      delay(delayTime);
      bright = bright - brightStep;
   } while (bright>=0);
  }
  
  for (int diode = ledCount-1; diode>=0;diode--) {
    int bright = 0;
    while (bright<brightness) {
      bright = bright + brightStep;
      if (bright>brightness) {
        bright = brightness;
      }

     Tlc.set(outs[diode], bright);
     Tlc.update();
     delay(delayTime);
   } ;
  } 
}