3 * (c) Tomas 'Harvie' Mudrunka 2016
7 #include <LiquidCrystal_I2C.h>
8 #include <TM1637Display.h>
11 #define BEEP_FREQ 3000
18 #define P_LEDSEG_CLK 2
19 #define P_LEDSEG_DIO 3
22 TM1637Display display(P_LEDSEG_CLK, P_LEDSEG_DIO);
23 LiquidCrystal_I2C lcd(0x3F, 16, 2); //i2c addr, chars, lines
45 boolean jumpers_read[JCOUNT][JCOUNT] = {0}, jumpers_secret[JCOUNT][JCOUNT] = {0};
47 void jumper_store(int a, int b, boolean c) {
48 jumpers_secret[min(a,b)][max(a,b)]=c;
51 void sound(char sndpin, float freq, float duration) { //Play bit-bang sound
52 if(duration<=0) return; if(freq<=0) { delay(duration); return; }
53 freq=((1000000/2)/freq); //Convert freq to delay (us)
54 duration*=1000; //Convert duration to us
55 pinMode(sndpin, OUTPUT);
56 for(;duration>0;duration-=2*freq) {
57 digitalWrite(sndpin, HIGH); delayMicroseconds(freq);
58 digitalWrite(sndpin, LOW); delayMicroseconds(freq);
60 pinMode(sndpin, INPUT); //Close pin to avoid noise (optional)
64 int i, j, check = 0, fail = 0;
66 for(i=0;i<JCOUNT;i++) {
67 pinMode(JBASE+i, OUTPUT);
68 digitalWrite(JBASE+i, LOW);
69 for(j=0;j<JCOUNT;j++) if(i<j) {
70 pinMode(JBASE+j, INPUT_PULLUP);
71 jumpers_read[i][j] = !digitalRead(JBASE+j);
72 if(jumpers_read[i][j]) {
74 Serial.print(JBASE+i, DEC);
76 Serial.print(JBASE+j, DEC);
77 if(jumpers_secret[i][j]) {
85 pinMode(JBASE+i, INPUT_PULLUP);
88 check = fail ? -check : check;
89 Serial.println(check, DEC);
94 jumper_store(J_A, J_5, true);
95 jumper_store(J_B, J_4, true);
96 jumper_store(J_C, J_7, true);
97 jumper_store(J_D, J_2, true);
98 jumper_store(J_E, J_6, true);
99 jumper_store(J_F, J_8, true);
100 jumper_store(J_G, J_1, true);
101 jumper_store(J_H, J_3, true);
103 pinMode(P_NASLAP, INPUT_PULLUP);
104 pinMode(P_RELAY_1, OUTPUT);
105 pinMode(P_RELAY_2, OUTPUT);
106 pinMode(P_LEDSTRIP, OUTPUT);
112 #define seconds_display(seconds) ((((seconds)/60)*100)+((seconds)%60))
114 // the loop function runs over and over again forever
116 Serial.println("Inicializace systemu...");
120 lcd.print(" (c) SPOJE.NET");
122 lcd.print("Tomas@MudrunkaCZ");
124 display.setBrightness(0x0f);
125 display.setColon(true);
126 display.showNumberDec(2323);
132 display.setBrightness(0x00);
134 display.setBrightness(0);
135 display.showNumberDec(0);
137 analogWrite(P_LEDSTRIP, 0);
138 digitalWrite(P_RELAY_1, HIGH);
139 digitalWrite(P_RELAY_2, HIGH);
141 sound(P_PIEZO, BEEP_FREQ, BEEP_LEN);
143 sound(P_PIEZO, BEEP_FREQ, BEEP_LEN);
144 Serial.println("Cekam na aktivaci...");
145 while(digitalRead(P_NASLAP));
147 Serial.println("Sekvence aktivovana!");
149 display.setBrightness(0x0f);
150 for(int i=0;i<70;i++) {
151 sound(P_PIEZO, random(500,10000), random(10,100));
152 display.showNumberDec(random(1000,9999));
153 analogWrite(P_LEDSTRIP, random(0,255));
155 sound(P_PIEZO, BEEP_FREQ, 2000);
157 Serial.println("Odpocet aktivovan!");
159 while(check_jumpers() != 8) {
160 Serial.print("Zbyva: ");
161 Serial.print(timer, DEC);
162 Serial.println(" sekund");
164 digitalWrite(P_RELAY_1, LOW);
166 display.setColon(timer%2);
167 display.showNumberDec(seconds_display(timer));
168 analogWrite(P_LEDSTRIP, map(timer%5, 0, 4, 255, 10));
169 digitalWrite(P_RELAY_2, timer%2);
172 sound(P_PIEZO, BEEP_FREQ, BEEP_LEN);
173 delay(1000-BEEP_LEN);
175 analogWrite(P_LEDSTRIP, random(0,255));
176 sound(P_PIEZO, random(500,10000), random(100,1000));
180 Serial.println("Odpocet zastaven.");
181 display.setColon(true);
182 display.showNumberDec(seconds_display(timer));
183 analogWrite(P_LEDSTRIP, 0);
184 digitalWrite(P_RELAY_1, HIGH);
186 //Muhammad Ismáil Árifi
188 lcd.print(" Muhammad");
190 lcd.print(" Ismail Arifi");
194 Serial.println("Cekam na reset...");
195 //while(digitalRead(P_NASLAP));
196 while(check_jumpers() != 0) delay(1000);