// Blikajici Hvezda - Demo // Pavel Kaspar, kaspar@pk.cz // version 0.02; 5.1.2022 /* ATTiny connections Leg Function 1 PB5, Reset, Output 2 PB3, Output 3 PB4, Output 4 GND 5 PB0 - Output 6 PB1 - Output 7 PB2 - Output 8 +5V */ unsigned long startMillis; unsigned long currentMillis; const unsigned long period = 100; void Nastav(byte Hodnota, int Cekej) { Hodnota = Hodnota & 0x3F; // 00xx xxxx PORTB = Hodnota; delay(Cekej); } void Rotace_ve_smeru(int Cekej) { // ve smeru hodinovych rucicek Nastav(B100000, Cekej); Nastav(B010000, Cekej); Nastav(B001000, Cekej); Nastav(B000100, Cekej); Nastav(B000010, Cekej); Nastav(B000001, Cekej); } void Rotace_proti_smeru(int Cekej) { // proti smeru hodinovych rucicek Nastav(B000001, Cekej); Nastav(B000010, Cekej); Nastav(B000100, Cekej); Nastav(B001000, Cekej); Nastav(B010000, Cekej); Nastav(B100000, Cekej); } // Inicializace void setup() { pinMode(0, OUTPUT); pinMode(1, OUTPUT); pinMode(2, OUTPUT); pinMode(3, OUTPUT); pinMode(4, OUTPUT); pinMode(5, OUTPUT); // Pro pouziti Reset Pinu je nutne zmenit Fuses. Nepujde ale ISP programovani PORTB = B00000000; } // Main void loop() { Nastav(B111111, 3000); // Plny svit Nastav(B000000, 500); for (unsigned int i=0; i<3; i++) { Rotace_ve_smeru(500); } Nastav(B000000, 500); for (unsigned int i=0; i<3; i++) { Rotace_proti_smeru(500); } Nastav(B000000, 500); for (unsigned int i=0; i<3; i++) { Nastav(B100000, 500); Nastav(B010000, 500); Nastav(B001000, 500); Nastav(B000100, 500); Nastav(B000010, 500); Nastav(B000001, 500); Nastav(B100001, 500); Nastav(B010001, 500); Nastav(B001001, 500); Nastav(B000101, 500); Nastav(B000011, 500); Nastav(B100011, 500); Nastav(B010011, 500); Nastav(B001011, 500); Nastav(B000111, 500); Nastav(B100111, 500); Nastav(B010111, 500); Nastav(B001111, 500); Nastav(B101111, 500); Nastav(B011111, 500); Nastav(B111111, 500); Nastav(B011111, 500); // A zase zpet Nastav(B101111, 500); Nastav(B001111, 500); Nastav(B010111, 500); Nastav(B100111, 500); Nastav(B000111, 500); Nastav(B001011, 500); Nastav(B010011, 500); Nastav(B100011, 500); Nastav(B000011, 500); Nastav(B000101, 500); Nastav(B001001, 500); Nastav(B010001, 500); Nastav(B100001, 500); Nastav(B000001, 500); Nastav(B000010, 500); Nastav(B000100, 500); Nastav(B001000, 500); Nastav(B010000, 500); Nastav(B100000, 500); Nastav(B000000, 500); } for (unsigned int j=0; j<3; j++) { for (unsigned int i=1; i<=100; i++) { // Postupne rozsveceni startMillis = millis(); do { PORTB = B00000000; delayMicroseconds(100-i); currentMillis = millis(); PORTB = B00111111; delayMicroseconds(i); PORTB = B00000000; } while (currentMillis - startMillis <= period); } PORTB = B00000000; for (unsigned int i=100; i>1; i--) { // Postupne zhasinani startMillis = millis(); do { PORTB = B00000000; delayMicroseconds(100-i); currentMillis = millis(); PORTB = B00111111; delayMicroseconds(i); PORTB = B00000000; } while (currentMillis - startMillis <= period); } } Nastav(B000000, 1000); Nastav(B111111, 50); Nastav(B000000, 500); Nastav(B111111, 50); Nastav(B000000, 500); for (unsigned int i=100; i>0; i--) { Rotace_ve_smeru(i); } for (unsigned int i=0; i<=100; i++) { Rotace_proti_smeru(i); } Nastav(B000000, 500); }