summaryrefslogtreecommitdiff
path: root/week4/week4.ino
blob: 14acb283a8d86f59f86fe9a7b6ba8bcef4f1308b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
void setup() {
	for (int i = 0; i < 8; ++i) pinMode(i, OUTPUT);
	analogReadResolution(8);
}

void loop() {
	int len = 0;
	int seq[1000];
	while (1) {
		seq[len++] = random(0, 4);
		for (int i = 0; i < len; ++i) {
			digitalWrite(seq[i]<<1|1, HIGH);
			delay(500);
			digitalWrite(seq[i]<<1|1, LOW);
			delay(500);
		}
		for (int i = 0; i < len; ++i) {
			while (analogRead(A0) < 240 && analogRead(A1) < 240 && analogRead(A2) < 240 && analogRead(A3) < 240);	
			for (int j = 0; j < 4; ++j)
				if (analogRead(A0+j) > 240 && seq[i] != j) goto DONE; // Legit use case of goto to jump out of 2 loops
			delay(500);
		}
		for (int i = 0; i < 8; ++i) {
			for (int j = 0; j < 4; ++j) digitalWrite(j<<1|1, i&1^1);
			delay(100);
		}
	}
	DONE:
	for (int i = 0; i < 8; ++i) {
		for (int j = 0; j < 4; ++j) digitalWrite(j<<1, i&1^1);
		delay(100);
	}
}