bLINK/Blink/Blink.ino
2019-12-30 12:45:58 +01:00

269 lines
4.6 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() {
// int test[] = {I, N, K};
// order(test, 200, false);
// off();
fromLeft(100);
toRight(100);
}
void off() {
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 time, bool keepEnd) {
int length = (int) (sizeof(list) / sizeof(int));
if(length == 0) {
return;
}
startLetter(list[0], time);
for (int 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 letters[] = {K, L, I, N, I, K};
order(letters, 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);
}