10-03-2019, 10:38
Witam,
Dziękuje za podpowiedz (poprawiłem błąd) ale wina była w czymś innym,
udało mi się poradzić z tym.
Teraz po podłączeniu zasilania światła mrugną i czekają na sygnał z czujników optycznych.
Przesyłam poprawiony w pełni działający kod:
Pozdrawiam
Dziękuje za podpowiedz (poprawiłem błąd) ale wina była w czymś innym,
udało mi się poradzić z tym.
Teraz po podłączeniu zasilania światła mrugną i czekają na sygnał z czujników optycznych.
Przesyłam poprawiony w pełni działający kod:
Pozdrawiam
Kod:
#include <Tlc5940.h>
const int downButtonPin = 6; // włącznik dolny
const int upButtonPin = 7; // włącznik górny
int downButtonState = 0; // status
int upButtonState = 0; //status
int ledCount = 16; //liczba aktywnych wyjść (światełek)
int brightness = 4095; //maksymalna jasność
int brightStep = 20; //krok przy rozjaśnianiu
int brightStep1 = 6; //krok przy ściemnianiu
int delayTime = 2; //szybkosc
int outs[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}; //wyjścia do których podpinane są taśmy
int outsState[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
void setup()
{
Tlc.init();
{
for (int diode=0; diode<ledCount; diode++)
Tlc.set(outs[diode], brightness-outs[diode]);
}
{
pinMode(downButtonPin, INPUT);
digitalWrite(downButtonPin, LOW);
pinMode(upButtonPin, INPUT);
digitalWrite(upButtonPin, LOW);
for (int diode = ledCount-1; diode>=0;diode--)
Tlc.set(outsState[diode], brightness-outs[diode]);
Tlc.update();
}
}
void loop()
{
for (int diode = ledCount-1; diode>=0;diode--)
Tlc.set(outs[diode], brightness-outsState[diode]);
Tlc.update();
{
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 + brightStep1;
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 + brightStep1;
if (bright>brightness) {
bright = brightness;
}
Tlc.set(outs[diode], bright);
Tlc.update();
delay(delayTime);
}
}
}