bLINK/Blink/Blink.ino

278 lines
4.8 KiB
C++

const int L = 3;
const int I = 5;
const int N = 4;
const int K = 6;
long randomTime;
void setup() {
pinMode(L, OUTPUT);
pinMode(I, OUTPUT);
pinMode(N, OUTPUT);
pinMode(K, OUTPUT);
}
void loop() {
klinik(150);
off();
int l1[] = {L,I,N,K};
order(l1, 4, 150, true);
order(l1, 3, 150, true);
order(l1, 2, 150, true);
order(l1, 1, 150, true);
off();
//fromLeft(100);
//toRight(100);
}
void off() {
digitalWrite(L, HIGH);
digitalWrite(I, HIGH);
digitalWrite(N, HIGH);
digitalWrite(K, HIGH);
delay(200);
digitalWrite(L, LOW);
digitalWrite(I, LOW);
digitalWrite(N, LOW);
digitalWrite(K, LOW);
delay(1000);
}
void startLetter(int letter, int time) {
digitalWrite(letter, HIGH);
delay(2 * time);
}
void endLetter(int letter, int time) {
delay(2 * time);
digitalWrite(letter, LOW);
}
void schng(int from, int to, int time) {
delay(2 * time);
digitalWrite(to, HIGH);
delay(time);
digitalWrite(from, LOW);
delay(2 * time);
}
void order(int list[], int length, int time, bool keepEnd) {
if(length == 0) {
return;
}
startLetter(list[0], time);
for (byte i = 1; i < length; i++) {
schng(list[i-1], list[i], time);
}
if(keepEnd) {
return;
}
endLetter(list[length], time);
}
void singleOn(int delayTime) {
digitalWrite(L, HIGH);
delay(delayTime);
digitalWrite(L, LOW);
digitalWrite(I, HIGH);
delay(delayTime);
digitalWrite(I, LOW);
digitalWrite(N, HIGH);
delay(delayTime);
digitalWrite(N, LOW);
digitalWrite(K, HIGH);
delay(delayTime);
digitalWrite(K, LOW);
}
void MiamiMidnight() {
digitalWrite(L, HIGH);
digitalWrite(I, HIGH);
digitalWrite(N, HIGH);
digitalWrite(K, HIGH);
randomTime = random(1000, 10000);
delay(randomTime);
digitalWrite(K, LOW);
delay(200);
digitalWrite(K, HIGH);
delay(400);
digitalWrite(I, LOW);
delay(200);
digitalWrite(I, HIGH);
delay(300);
digitalWrite(K, LOW);
delay(900);
}
void klinik(int time) {
int length = 6;
int letters[] = {K, L, I, N, I, K};
order(letters, length, time, false);
delay(1000);
}
void fromLeft(int del) {
digitalWrite(L, HIGH);
delay(del);
digitalWrite(I, HIGH);
delay(del/4);
digitalWrite(L, LOW);
delay(del);
digitalWrite(N, HIGH);
delay(del/4);
digitalWrite(I, LOW);
delay(del);
digitalWrite(K, HIGH);
delay(del/4);
digitalWrite(N, LOW);
delay(del*2);
digitalWrite(L, HIGH);
delay(del);
digitalWrite(I, HIGH);
delay(del/4);
digitalWrite(L, LOW);
delay(del);
digitalWrite(N, HIGH);
delay(del/4);
digitalWrite(I, LOW);
delay(del*2);
digitalWrite(L, HIGH);
delay(del);
digitalWrite(I, HIGH);
delay(del/4);
digitalWrite(L, LOW);
delay(del*2);
digitalWrite(L, HIGH);
delay(3000);
}
void fromRight(int del) {
digitalWrite(K, HIGH);
delay(del);
digitalWrite(N, HIGH);
delay(del/4);
digitalWrite(K, LOW);
delay(del);
digitalWrite(I, HIGH);
delay(del/4);
digitalWrite(N, LOW);
delay(del);
digitalWrite(L, HIGH);
delay(del/4);
digitalWrite(I, LOW);
delay(del*2);
digitalWrite(K, HIGH);
delay(del);
digitalWrite(N, HIGH);
delay(del/4);
digitalWrite(K, LOW);
delay(del);
digitalWrite(I, HIGH);
delay(del/4);
digitalWrite(N, LOW);
delay(del*2);
digitalWrite(K, HIGH);
delay(del);
digitalWrite(N, HIGH);
delay(del/4);
digitalWrite(K, LOW);
delay(del*2);
digitalWrite(K, HIGH);
delay(3000);
}
void toLeft(int del) {
digitalWrite(L, HIGH);
digitalWrite(I, HIGH);
digitalWrite(N, HIGH);
digitalWrite(K, HIGH);
digitalWrite(L, LOW);
delay(del*2);
digitalWrite(L, HIGH);
delay(del/4);
digitalWrite(I, LOW);
delay(del);
digitalWrite(L, LOW);
delay(del*2);
digitalWrite(I, HIGH);
delay(del/4);
digitalWrite(N, LOW);
delay(del);
digitalWrite(L, HIGH);
delay(del/4);
digitalWrite(I, LOW);
delay(del);
digitalWrite(L, LOW);
delay(del*2);
digitalWrite(N, HIGH);
delay(del/4);
digitalWrite(K, LOW);
delay(del);
digitalWrite(I, HIGH);
delay(del/4);
digitalWrite(N, LOW);
delay(del);
digitalWrite(L, HIGH);
delay(del/4);
digitalWrite(I, LOW);
delay(del);
digitalWrite(L, LOW);
delay(3000);
}
void toRight(int del) {
digitalWrite(L, HIGH);
digitalWrite(I, HIGH);
digitalWrite(N, HIGH);
digitalWrite(K, HIGH);
digitalWrite(K, LOW);
delay(del*2);
digitalWrite(K, HIGH);
delay(del/4);
digitalWrite(N, LOW);
delay(del);
digitalWrite(K, LOW);
delay(del*2);
digitalWrite(N, HIGH);
delay(del/4);
digitalWrite(I, LOW);
delay(del);
digitalWrite(K, HIGH);
delay(del/4);
digitalWrite(N, LOW);
delay(del);
digitalWrite(K, LOW);
delay(del*2);
digitalWrite(I, HIGH);
delay(del/4);
digitalWrite(L, LOW);
delay(del);
digitalWrite(N, HIGH);
delay(del/4);
digitalWrite(I, LOW);
delay(del);
digitalWrite(K, HIGH);
delay(del/4);
digitalWrite(N, LOW);
delay(del);
digitalWrite(K, LOW);
delay(3000);
}