LED Heart fotoram - gör en perfekt alla hjärtans eller födelsedagspresent (6 / 7 steg)
Steg 6: Arduino kod
För detta projekt använde jag TLC5940 biblioteket av Alex Leone. Du behöver att göra några ändringar när du använder biblioteket med två TLC5940 ICs. Måste du ändra filen tlc_config.h och ändra värdet på variabeln NUM_TLCS till värdet 2.
Här är den kompletta Arduino koden:
< br >< p > / * LED Heart fotoram - Arduino projekt < br > * Program från Dejan Nedelkovski,
* www.HowToMechatronics.com
* < /p >< p > * TLC5940 bibliotek av Alex Leone, https://code.google.com/archive/p/tlc5940arduino/
* Du måste ändra tlc_config.h i TLC5940 biblioteket
* och ändra värdet på variabeln NUM_TLCS till numrerar av TLC5940 ICs ansluten
* / < /p >< p > #include "Tlc5940.h" < /p >< p > int scenen = 0;
int randomNumber;
int count = 0;
int ljusstyrka = 3500;
int brightUp = 50;
int dir = 1; < /p >< p > void setup() {
TLC.init();
} < /p >< p > void loop() {
Switch(Stage) {
---Steg 1
fall 0:
randomNumber = (int)random(0,31);
TLC.set(randomNumber,4095);
Delay(1500);
TLC.Update();
om (count > = 8) {
steg = 1;
Count = 0;
}
annat {
++ räkna;
}
bryta;
---Etapp 2
fall 1:
Delay(75);
för (int jag = 31; jag > = 0; i--) {
TLC.set(i,4095);
Delay(100);
TLC.Update();
}
Delay(500);
TLC.Clear();
TLC.Update();
steg = 2;
Delay(500);
bryta;
---Etapp 3
fall 2:
för (int jag = 0; jag < = 31; i ++) {
TLC.set(i,4095);
}
TLC.Update();
Delay(500);
TLC.Clear();
TLC.Update();
Delay(350);
om (count > 6) {
steg = 3;
Count = 0;
}
annat {
++ räkna;
}
bryta;
---Etapp 4
fall 3:
för (int jag = 0; jag < = 15; i ++) {
TLC.set(i,4095);
TLC.set(31-i,4095);
TLC.Update();
Delay(70);
}
Delay(50);
för (int jag = 15; jag > = 0; i--) {
TLC.set(i,0);
TLC.set(31-i,0);
TLC.Update();
Delay(70);
}
för (int jag = 15; jag > = 0; i--) {
TLC.set(i,4095);
TLC.set(31-i,4095);
TLC.Update();
Delay(70);
}
för (int jag = 0; jag < = 15; i ++) {
TLC.set(i,0);
TLC.set(31-i,0);
TLC.Update();
Delay(70);
}
Delay(50);
TLC.Clear();
TLC.Update();
Delay(100);
om (count > 1) {
steg = 4;
Count = 0;
}
annat {
++ räkna;
}
bryta;
---Etapp 5
fall 4:
för (int jag = 15; jag > = räkna; i--) {
TLC.set(32-i,4095);
TLC.Update();
Delay(5);
TLC.set(32-i-1,0);
TLC.Update();
Delay(5);
TLC.set(i,4095);
TLC.Update();
Delay(5);
TLC.set(i+1,0);
TLC.Update();
Delay(50);
}
om (count > 15) {
TLC.set(16,4095);
TLC.Update();
Delay(2000);
steg = 5;
Count = 0;
}
annat {
++ räkna;
}
bryta;
---Etapp 6
fall 5:
för (int jag = 0; jag < = 31; i ++) {
TLC.set(i,Brightness);
TLC.Update();
}
TLC.Update();
ljusstyrka = ljusstyrka + brightUp;
om (ljusstyrka > = 3500) {
brightUp =-50;
++ räkna;
}
om (ljusstyrka < = 150) {
brightUp = 50;
}
om (count > 6) {
steg = 6;
Count = 0;
ljusstyrka = 3500;
TLC.Clear();
TLC.Update();
}
Delay(40);
bryta;
---Steg 7
fall 6:
för (int jag = 0; jag < = 30; jag += 2) {
TLC.set(i,4095);
TLC.set(i+1,0);
}
TLC.Update();
Delay(500);
för (int jag = 0; jag < = 30; jag += 2) {
TLC.set(i,0);
TLC.set(i+1,4095);
}
TLC.Update();
Delay(500);
om (count > 20) {
steg = 7.
Count = 0;
}
annat {
++ räkna;
}
bryta;
---Etapp 8
fall 7:
för (int jag = 31; jag > = 16; i--) {
TLC.Clear();
TLC.Update();
Delay(2);
TLC.set(i,4095);
TLC.set(i+1,2000);
TLC.set(i+2,1000);
TLC.set(i+3,500);
TLC.set(i+4,300);
TLC.set(i+5,200);
TLC.set(i+6,100);
TLC.set(i+7,50);
TLC.set(i+8,0); < /p >< p > Tlc.set(i-16,4095);
TLC.set(i-15,2000);
TLC.set(i-14,1000);
TLC.set(i-13,500);
TLC.set(i-12,300);
TLC.set(i-11,200);
TLC.set(i-10,100);
TLC.set(i+-9,50);
TLC.set(i-8,0);
TLC.Update();
Delay(50);
}
om (count > 8) {
för (int jag = 31; jag > = 0; i--) {
TLC.set(i,4095);
TLC.Update();
Delay(50);
}
steg = 8.
Count = 0;
}
annat {
++ räkna;
}
bryta;
---Steg 9
mål 8:
för (int jag = 31; jag > = 0; i--) {
TLC.set(i+8,4095);
TLC.set(i+7,2000);
TLC.set(i+6,1000);
TLC.set(i+5,500);
TLC.set(i+4,300);
TLC.set(i+3,200);
TLC.set(i+2,100);
TLC.set(i+1,50);
TLC.set(i,0);
TLC.Update();
Delay(50);
}
för (int jag = 31; jag > = 0; i--) {
TLC.set(i,4095);
}
TLC.Update();
Delay(10);
om (count > 8) {
Delay(8000);
TLC.Clear();
TLC.Update();
steg = 0;
Count = 0;
}
annat {
++ räkna;
}
bryta;
}
} < /p >