From: Tomas Mudrunka Date: Sat, 30 Oct 2021 12:12:24 +0000 (+0200) Subject: Presun starych X-Git-Url: https://git.harvie.cz/?a=commitdiff_plain;h=de8021a10a2d637bb82fcfbf59ab419605f2ae0e;p=mirrors%2FPrograms.git Presun starych --- diff --git a/arduino/bomba-keypad/bomba-keypad.ino b/arduino/bomba-keypad/bomba-keypad.ino deleted file mode 100644 index 179d432..0000000 --- a/arduino/bomba-keypad/bomba-keypad.ino +++ /dev/null @@ -1,161 +0,0 @@ -/* - * PS2 pinout cinskej kabel: data cerveny (18), clock bily (19), 5V cerny, GND zluty - */ - -#define SOFTSERIAL - -#ifndef SOFTSERIAL -#include -PS2dev keyboard(19, 18); //clock, data -#else -#include -//#include -SoftwareSerial mySerial(18, 19); -#endif - -#include - -LedControl lc=LedControl(16,14,15,2); //datain, clk, load, number of chips -unsigned char dispbuf[32]; - -#include - -int keyledPin = 3; - -const byte ROWS = 4; //four rows -const byte COLS = 3; //four columns -//define the cymbols on the buttons of the keypads -char hexaKeys[ROWS][COLS] = { - {'1','2','3'}, - {'4','5','6'}, - {'7','8','9'}, - {'*','0','#'} -}; -byte rowPins[ROWS] = {10, 9, 8, 7}; //connect to the row pinouts of the keypad -byte colPins[COLS] = {4, 5, 6}; //connect to the column pinouts of the keypad - -//initialize an instance of class NewKeypad -Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS); - -char scancodes[] = {0x45, 0x16, 0x1E, 0x26, 0x25, 0x2E, 0x36, 0x3D, 0x3E, 0x46, 0x7C, 0x7C}; //Scancodes for numbers 0-9, *, # - -void cleardisp(char val) { - for(int i = 0; i<8; i++) dispbuf[i] = val; -} - -void drawdisp(int shift) { - lc.clearDisplay(0); - for(int i = 0; i<8; i++) { - if(shift) dispbuf[i] = dispbuf[i+1]; - if(dispbuf[i] != '_') lc.setDigit(0,7-i,dispbuf[i],false); //addr, digit, value, decimalpoint - } -} - -void intro() { - cleardisp('_'); - for(int i = 0; i<100; i++) { - analogWrite(keyledPin, i); - if(i >= 20*1) dispbuf[3] = dispbuf[4] = 0; - if(i >= 20*2) dispbuf[2] = dispbuf[5] = 0; - if(i >= 20*3) dispbuf[1] = dispbuf[6] = 0; - if(i >= 20*4) dispbuf[0] = dispbuf[7] = 0; - drawdisp(0); - delay(20); - } -} - -void outro() { - cleardisp(0); - for(int i = 100; i>=0; i--) { - analogWrite(keyledPin, i); - if(i <= 20*1) dispbuf[3] = dispbuf[4] = '_'; - if(i <= 20*2) dispbuf[2] = dispbuf[5] = '_'; - if(i <= 20*3) dispbuf[1] = dispbuf[6] = '_'; - if(i <= 20*4) dispbuf[0] = dispbuf[7] = '_'; - drawdisp(0); - delay(20); - } -} - - -void setup(){ - /* - The MAX72XX is in power-saving mode on startup, - we have to do a wakeup call - */ - lc.shutdown(0,false); - /* Set the brightness to a medium values */ - lc.setIntensity(0,15); //0 - 15 - /* and clear the display */ - lc.clearDisplay(0); - - intro(); - cleardisp('_'); drawdisp(0); - -#ifndef SOFTSERIAL - // send the keyboard start up - keyboard.keyboard_init(); -#else - mySerial.begin(4800); -#endif - - Serial.begin(9600); - - - - pinMode(LED_BUILTIN, OUTPUT); -} - -void loop(){ - unsigned char leds; -#ifndef SOFTSERIAL - if(keyboard.keyboard_handle(&leds)) { - //Serial.print('LEDS'); - //Serial.print(leds, HEX); - digitalWrite(LED_BUILTIN, leds); - } -#endif - - char customKey = customKeypad.getKey(); - - if (customKey){ - Serial.println(customKey); - //analogWrite(keyledPin, random(0, 255)); - analogWrite(keyledPin, 255); - unsigned char numkey = customKey-0x30; - if(numkey < 10) { -#ifndef SOFTSERIAL - //Send PS2 - keyboard.keyboard_mkbrk(scancodes[numkey]); -#else - mySerial.print(customKey); -#endif - - //Single digit - //lc.setDigit(0,7,numkey,false); //addr, digit, value, decimalpoint - - //Scroll out display - dispbuf[8] = numkey; - drawdisp(1); - } - } - - if (customKey == '*') { - //Send PS2 -#ifndef SOFTSERIAL - keyboard.keyboard_mkbrk(scancodes[10]); -#endif - - //analogWrite(keyledPin, 0); - outro(); - - cleardisp('_'); - drawdisp(0); - } - - if (customKey == '#') { -#ifndef SOFTSERIAL - keyboard.keyboard_mkbrk(0x5A); //enter -#endif - } -} diff --git a/arduino/bomba-ledtest/bomba-ledtest.ino b/arduino/bomba-ledtest/bomba-ledtest.ino deleted file mode 100644 index f0f9f7a..0000000 --- a/arduino/bomba-ledtest/bomba-ledtest.ino +++ /dev/null @@ -1,68 +0,0 @@ -#include - -LedControl lc=LedControl(16,14,15,2); //datain, clk, load, number of chips - -/* we always wait a bit between updates of the display */ -unsigned long delaytime=250; - -void setup() { - /* - The MAX72XX is in power-saving mode on startup, - we have to do a wakeup call - */ - lc.shutdown(0,false); - /* Set the brightness to a medium values */ - lc.setIntensity(0,15); //0 - 15 - /* and clear the display */ - lc.clearDisplay(0); -} - - -/* - This method will display the characters for the - word "Arduino" one after the other on digit 0. - */ -void writeArduinoOn7Segment() { - lc.setChar(0,0,'a',false); - delay(delaytime); - lc.setRow(0,0,0x05); - delay(delaytime); - lc.setChar(0,0,'d',false); - delay(delaytime); - lc.setRow(0,0,0x1c); - delay(delaytime); - lc.setRow(0,0,B00010000); - delay(delaytime); - lc.setRow(0,0,0x15); - delay(delaytime); - lc.setRow(0,0,0x1D); - delay(delaytime); - lc.clearDisplay(0); - delay(delaytime); -} - -/* - This method will scroll all the hexa-decimal - numbers and letters on the display. You will need at least - four 7-Segment digits. otherwise it won't really look that good. - */ -void scrollDigits() { - for(int i=0;i<13;i++) { - lc.setDigit(0,7,i,false); - lc.setDigit(0,6,i+1,false); - lc.setDigit(0,5,i+2,false); - lc.setDigit(0,4,i+3,false); - lc.setDigit(0,3,i+4,false); - lc.setDigit(0,2,i+5,false); - lc.setDigit(0,1,i+6,false); - lc.setDigit(0,0,i+7,false); - delay(delaytime); - } - lc.clearDisplay(0); - delay(delaytime); -} - -void loop() { - writeArduinoOn7Segment(); - scrollDigits(); -} diff --git a/arduino/bomba-ps2test/bomba-ps2test.ino b/arduino/bomba-ps2test/bomba-ps2test.ino deleted file mode 100644 index 57160a3..0000000 --- a/arduino/bomba-ps2test/bomba-ps2test.ino +++ /dev/null @@ -1,26 +0,0 @@ -#include - -PS2dev keyboard(19, 18); //clock, data - -void make_break_kb(byte data) -{ -// makes and breaks the key - keyboard.write(data); - delay(50); - keyboard.write(0xF0); - delay(50); - keyboard.write(data); - delay(50); -} - -void setup() { -} - -char scancodes[] = {0x45, 0x16, 0x1E, 0x26, 0x25, 0x2E, 0x36, 0x3D, 0x3E, 0x46, 0x7C, 0x7C}; //Scancodes for numbers 0-9, *, # - -void loop() { - for(int i = 0; i < 11; i++) { - make_break_kb(scancodes[i]); - delay(1000); - } -} diff --git a/arduino/bomba2/bomba2.ino/bomba2.ino.ino b/arduino/bomba2/bomba2.ino/bomba2.ino.ino deleted file mode 100644 index b104cc7..0000000 --- a/arduino/bomba2/bomba2.ino/bomba2.ino.ino +++ /dev/null @@ -1,104 +0,0 @@ -/* -*/ - -//Nastaveni bomby - -#define TIME_COUNTDOWN 600 - - -//Prirazeni pinu - -#define PIN_CABLE_CHECK 2 - -#define PIN_KEY_CLK 3 //IRQ! -#define PIN_KEY_DATA 4 - -#define PIN_LED_R 5 -#define PIN_LED_G 6 -#define PIN_LED_B 7 - -#define PIN_COIL_LO 10 -#define PIN_COIL_HI 11 - -#define ADDR_DISPLAY 0x70 - -////////////////////////////////////////////////////////////////// - -#include - -//#include // Enable this line if using Arduino Uno, Mega, etc. -#include -#include "Adafruit_LEDBackpack.h" - -PS2Keyboard keyboard; -Adafruit_7segment display = Adafruit_7segment(); - -void setup() { - Serial.begin(9600); - Serial.println("Keyboard Test:"); - - keyboard.begin(PIN_KEY_DATA, PIN_KEY_CLK); - - display.begin(ADDR_DISPLAY); - display.clear(); - //display.writeDisplay(); - - pinMode(PIN_LED_R, OUTPUT); - pinMode(PIN_LED_G, OUTPUT); - pinMode(PIN_LED_B, OUTPUT); - pinMode(PIN_COIL_LO, OUTPUT); - pinMode(PIN_COIL_HI, OUTPUT); - pinMode(PIN_CABLE_CHECK, INPUT_PULLUP); -} - -void loop() { - if (keyboard.available()) { - - // read the next key - char c = keyboard.read(); - - // check for some of the special keys - if (c == PS2_ENTER) { - Serial.println(); - } else { - Serial.print(c); - } - - if(digitalRead(PIN_CABLE_CHECK)) c+=16; - display.print(c, HEX); - display.drawColon(c%2); - //display.setBrightness(random(0,15)); - display.setBrightness(0); - //display.clear(); - display.writeDisplay(); - - - if(c%2) { - analogWrite(PIN_LED_R, random(0,255)); // turn the LED on (HIGH is the voltage level) - analogWrite(PIN_LED_G, random(0,255)); // turn the LED on (HIGH is the voltage level) - analogWrite(PIN_LED_B, random(0,255)); // turn the LED on (HIGH is the voltage level) - digitalWrite(PIN_COIL_HI, HIGH); // turn the LED on (HIGH is the voltage level) - } else { - digitalWrite(PIN_COIL_LO, HIGH); // turn the LED on (HIGH is the voltage level) - digitalWrite(PIN_LED_R, LOW); // turn the LED on (HIGH is the voltage level) - digitalWrite(PIN_LED_G, LOW); // turn the LED on (HIGH is the voltage level) - digitalWrite(PIN_LED_B, LOW); // turn the LED on (HIGH is the voltage level) - } - delay(random(1,15)); // wait for a second - digitalWrite(PIN_COIL_LO, LOW); // turn the LED off by making the voltage LOW - digitalWrite(PIN_COIL_HI, LOW); // turn the LED off by making the voltage LOW - - if(c == '.') { - int d = random(100,1000); - for(int i = 0; i < 1000; i++) { - - digitalWrite(PIN_COIL_LO, HIGH); //digitalWrite(11, HIGH); - delayMicroseconds(d/2); - digitalWrite(PIN_COIL_LO, LOW); //digitalWrite(11, LOW); - delayMicroseconds(d/2); - } - } - } - - -} diff --git a/arduino/bomba2/bomba2b/bomba2b.ino b/arduino/bomba2/bomba2b/bomba2b.ino deleted file mode 100644 index b104cc7..0000000 --- a/arduino/bomba2/bomba2b/bomba2b.ino +++ /dev/null @@ -1,104 +0,0 @@ -/* -*/ - -//Nastaveni bomby - -#define TIME_COUNTDOWN 600 - - -//Prirazeni pinu - -#define PIN_CABLE_CHECK 2 - -#define PIN_KEY_CLK 3 //IRQ! -#define PIN_KEY_DATA 4 - -#define PIN_LED_R 5 -#define PIN_LED_G 6 -#define PIN_LED_B 7 - -#define PIN_COIL_LO 10 -#define PIN_COIL_HI 11 - -#define ADDR_DISPLAY 0x70 - -////////////////////////////////////////////////////////////////// - -#include - -//#include // Enable this line if using Arduino Uno, Mega, etc. -#include -#include "Adafruit_LEDBackpack.h" - -PS2Keyboard keyboard; -Adafruit_7segment display = Adafruit_7segment(); - -void setup() { - Serial.begin(9600); - Serial.println("Keyboard Test:"); - - keyboard.begin(PIN_KEY_DATA, PIN_KEY_CLK); - - display.begin(ADDR_DISPLAY); - display.clear(); - //display.writeDisplay(); - - pinMode(PIN_LED_R, OUTPUT); - pinMode(PIN_LED_G, OUTPUT); - pinMode(PIN_LED_B, OUTPUT); - pinMode(PIN_COIL_LO, OUTPUT); - pinMode(PIN_COIL_HI, OUTPUT); - pinMode(PIN_CABLE_CHECK, INPUT_PULLUP); -} - -void loop() { - if (keyboard.available()) { - - // read the next key - char c = keyboard.read(); - - // check for some of the special keys - if (c == PS2_ENTER) { - Serial.println(); - } else { - Serial.print(c); - } - - if(digitalRead(PIN_CABLE_CHECK)) c+=16; - display.print(c, HEX); - display.drawColon(c%2); - //display.setBrightness(random(0,15)); - display.setBrightness(0); - //display.clear(); - display.writeDisplay(); - - - if(c%2) { - analogWrite(PIN_LED_R, random(0,255)); // turn the LED on (HIGH is the voltage level) - analogWrite(PIN_LED_G, random(0,255)); // turn the LED on (HIGH is the voltage level) - analogWrite(PIN_LED_B, random(0,255)); // turn the LED on (HIGH is the voltage level) - digitalWrite(PIN_COIL_HI, HIGH); // turn the LED on (HIGH is the voltage level) - } else { - digitalWrite(PIN_COIL_LO, HIGH); // turn the LED on (HIGH is the voltage level) - digitalWrite(PIN_LED_R, LOW); // turn the LED on (HIGH is the voltage level) - digitalWrite(PIN_LED_G, LOW); // turn the LED on (HIGH is the voltage level) - digitalWrite(PIN_LED_B, LOW); // turn the LED on (HIGH is the voltage level) - } - delay(random(1,15)); // wait for a second - digitalWrite(PIN_COIL_LO, LOW); // turn the LED off by making the voltage LOW - digitalWrite(PIN_COIL_HI, LOW); // turn the LED off by making the voltage LOW - - if(c == '.') { - int d = random(100,1000); - for(int i = 0; i < 1000; i++) { - - digitalWrite(PIN_COIL_LO, HIGH); //digitalWrite(11, HIGH); - delayMicroseconds(d/2); - digitalWrite(PIN_COIL_LO, LOW); //digitalWrite(11, LOW); - delayMicroseconds(d/2); - } - } - } - - -} diff --git a/arduino/bomba2b/bomba2b.ino b/arduino/bomba2b/bomba2b.ino deleted file mode 100644 index 5c49c1c..0000000 --- a/arduino/bomba2b/bomba2b.ino +++ /dev/null @@ -1,219 +0,0 @@ -/* - * Exit Rum 2 - * (c) Tomas 'Harvie' Mudrunka 2018 - */ - -//Nastaveni bomby - -#define DISARM_CODE "73138477" -#define TIME_COUNTDOWN 600 //600 -//#define TIME_COUNTDOWN 15 - -//Prirazeni pinu - -#define PIN_CABLE_CHECK 2 - -#define PIN_KEY_CLK 3 //IRQ! -#define PIN_KEY_DATA 4 - -#define PIN_LED_G 5 -#define PIN_LED_B 6 -#define PIN_LED_R 7 - -#define PIN_COIL_LO 10 -#define PIN_COIL_HI 11 - -#define ADDR_DISPLAY 0x70 - -////////////////////////////////////////////////////////////////// - -#define SOFTSERIAL - -#ifndef SOFTSERIAL -#include -PS2Keyboard keyboard; -#else -#include -SoftwareSerial mySerial(PIN_KEY_CLK, PIN_KEY_DATA); -#endif - -//#include // Enable this line if using Arduino Uno, Mega, etc. -#include -#include "Adafruit_LEDBackpack.h" - -Adafruit_7segment display = Adafruit_7segment(); - -#define cnt_sec(s) (s%60) -#define cnt_min(s) (s/60) -#define cnt_dec(s) (cnt_min(s)*100+cnt_sec(s)) - -void setup() -{ - //Pripravime periferie - Serial.begin(9600); - Serial.println("zaciname"); -#ifndef SOFTSERIAL - keyboard.begin(PIN_KEY_DATA, PIN_KEY_CLK); -#else - mySerial.begin(4800); -#endif - display.begin(ADDR_DISPLAY); - - pinMode(PIN_LED_R, OUTPUT); - pinMode(PIN_LED_G, OUTPUT); - pinMode(PIN_LED_B, OUTPUT); - pinMode(PIN_COIL_LO, OUTPUT); - pinMode(PIN_COIL_HI, OUTPUT); - pinMode(PIN_CABLE_CHECK, INPUT_PULLUP); -} - -int test_disarmed(int reset) -{ - - static int guessed = 0, disarmed = 0; - if (reset) { - guessed = 0; - disarmed = 0; - } - //Cteme klavesnici -#ifndef SOFTSERIAL - while (keyboard.available()) { - char c = keyboard.read(); - //Serial.print("Klavesa: "); - //Serial.println(c); -#else - while (mySerial.available()) { - char c = mySerial.read(); -#endif -#ifndef SOFTSERIAL - if (c == PS2_ENTER) { - Serial.println(); - } else { -#else - if(1) { -#endif - Serial.print(c); - } - - if (c < '0' || c > '9') { - Serial.println("IGNORED!"); - continue; - - } - if (c == DISARM_CODE[guessed]) { - guessed++; - Serial.println("\nGOT!"); - } else { - guessed = 0; - Serial.println("\nFAIL!"); - if (c == DISARM_CODE[guessed]) { - guessed++; - Serial.println("\nGOT!"); - } - } - if (DISARM_CODE[guessed] == 0) { - disarmed = 1; - Serial.println("\nDISARMED!"); - } - } - - return disarmed; - -} - -void loop() -{ - //Vynulujem periferie - digitalWrite(PIN_COIL_LO, LOW); - digitalWrite(PIN_COIL_HI, LOW); - analogWrite(PIN_LED_R, 0); - analogWrite(PIN_LED_G, 0); - analogWrite(PIN_LED_B, 0); - - display.clear(); - display.setBrightness(15); - display.writeDisplay(); - -#ifndef SOFTSERIAL - while (keyboard.available()) - keyboard.read(); -#else - while (mySerial.available()) - mySerial.read(); -#endif - test_disarmed(1); - - //Pockame na pripojeni kabelu - display.print(0xCAB1, HEX); - display.writeDisplay(); - while (digitalRead(PIN_CABLE_CHECK)) - delay(100); - - //Pockame na odpojeni kabelu - display.clear(); - display.writeDisplay(); - while (!digitalRead(PIN_CABLE_CHECK)) - delay(100); - - //Odpocitavame - for (int cnt = TIME_COUNTDOWN; cnt >= 0 && !test_disarmed(0); cnt--) { - display.print(cnt_dec(cnt), DEC); - display.drawColon((cnt + 1) % 2); - display.writeDisplay(); - - analogWrite(PIN_LED_R, random(0, 3)); - analogWrite(PIN_LED_G, random(0, 3)); - analogWrite(PIN_LED_B, random(0, 3)); - - //Tikani / pipani - tone(PIN_COIL_LO, 1000, 50); - delay(60); - digitalWrite(PIN_COIL_LO, HIGH); - delay(40); - digitalWrite(PIN_COIL_LO, LOW); - - delay(900); - - } - - - while (!test_disarmed(0)) { - //Bomba vybouchla - int i; - - analogWrite(PIN_LED_R, random(0, 255)); - analogWrite(PIN_LED_G, random(0, 0)); - analogWrite(PIN_LED_B, random(0, 255)); - - for (i = 0; i < 10; i++) - display.writeDigitRaw(i, random(0, 255)); - display.setBrightness(random(0, 15)); - display.writeDisplay(); - - digitalWrite(PIN_COIL_HI, HIGH); - delay(20); - digitalWrite(PIN_COIL_HI, LOW); - int rnd = random(30, 100); - tone(PIN_COIL_LO, random(100, 8000), rnd); - delay(rnd); - } - - - //Bomba byla deaktivovana - tone(PIN_COIL_LO, 3000, 500); - delay(500); - tone(PIN_COIL_LO, 5000, 500); - analogWrite(PIN_LED_R, 0); - analogWrite(PIN_LED_G, 0); - analogWrite(PIN_LED_B, 0); - display.print(0xDEFD, HEX); - display.writeDisplay(); - delay(1000); - - - //Pockame na zmenu kabelu - char s = digitalRead(PIN_CABLE_CHECK); - while (digitalRead(PIN_CABLE_CHECK) == s) - delay(100); - -} diff --git a/arduino/exit-rum-display/exit-rum-display.ino b/arduino/exit-rum-display/exit-rum-display.ino deleted file mode 100644 index 68e420b..0000000 --- a/arduino/exit-rum-display/exit-rum-display.ino +++ /dev/null @@ -1,44 +0,0 @@ -#include -#include -#include - -// Module connection pins (Digital Pins) -#define CLK 2 -#define DIO 3 - -TM1637Display display(CLK, DIO); - -// Set the LCD address to 0x27 for a 16 chars and 2 line display -LiquidCrystal_I2C lcd(0x3F, 16, 2); - -int i; - -void setup() -{ - // initialize the LCD - lcd.begin(); - - // Turn on the blacklight and print a message. - lcd.backlight(); - lcd.print("Rychta pyco!"); - - display.setBrightness(0x0f); - display.setColon(true); - display.showNumberDec(23); - - pinMode(8, OUTPUT); - pinMode(9, OUTPUT); - -} - -void loop() -{ - digitalWrite(8, HIGH); // turn the LED on (HIGH is the voltage level) - display.setColon(true); - display.showNumberDec(i); - delay(1000); - digitalWrite(8, LOW); // turn the LED off by making the voltage LOW - display.setColon(false); - display.showNumberDec(i++); - delay(1000); -} diff --git a/arduino/exit-rum/exit-rum.ino b/arduino/exit-rum/exit-rum.ino deleted file mode 100644 index bffa260..0000000 --- a/arduino/exit-rum/exit-rum.ino +++ /dev/null @@ -1,197 +0,0 @@ -/* - * Exit Rum - * (c) Tomas 'Harvie' Mudrunka 2016 - */ - -#include -#include -#include - -#define TIMEOUT 300 -#define BEEP_FREQ 3000 -#define BEEP_LEN 50 - -#define P_NASLAP 12 -#define P_PIEZO 35 -#define P_RELAY_1 9 -#define P_RELAY_2 8 -#define P_LEDSEG_CLK 2 -#define P_LEDSEG_DIO 3 -#define P_LEDSTRIP 11 - -TM1637Display display(P_LEDSEG_CLK, P_LEDSEG_DIO); -LiquidCrystal_I2C lcd(0x3F, 16, 2); //i2c addr, chars, lines - -#define JBASE 38 -#define JCOUNT 16 - -#define J_A 0 -#define J_B 2 -#define J_C 4 -#define J_D 6 -#define J_E 8 -#define J_F 10 -#define J_G 12 -#define J_H 14 -#define J_1 1 -#define J_2 3 -#define J_3 5 -#define J_4 7 -#define J_5 9 -#define J_6 11 -#define J_7 13 -#define J_8 15 - -boolean jumpers_read[JCOUNT][JCOUNT] = {0}, jumpers_secret[JCOUNT][JCOUNT] = {0}; - -void jumper_store(int a, int b, boolean c) { - jumpers_secret[min(a,b)][max(a,b)]=c; -} - -void sound(char sndpin, float freq, float duration) { //Play bit-bang sound - if(duration<=0) return; if(freq<=0) { delay(duration); return; } - freq=((1000000/2)/freq); //Convert freq to delay (us) - duration*=1000; //Convert duration to us - pinMode(sndpin, OUTPUT); - for(;duration>0;duration-=2*freq) { - digitalWrite(sndpin, HIGH); delayMicroseconds(freq); - digitalWrite(sndpin, LOW); delayMicroseconds(freq); - } - pinMode(sndpin, INPUT); //Close pin to avoid noise (optional) -} - -int check_jumpers() { - int i, j, check = 0, fail = 0; - - for(i=0;i"); - Serial.print(JBASE+j, DEC); - if(jumpers_secret[i][j]) { - Serial.print("!"); - } else { - fail++; - } - Serial.print(", "); - } - } - pinMode(JBASE+i, INPUT_PULLUP); - } - Serial.println(); - check = fail ? -check : check; - Serial.println(check, DEC); - return check; -} - -void setup() { - jumper_store(J_A, J_5, true); - jumper_store(J_B, J_4, true); - jumper_store(J_C, J_7, true); - jumper_store(J_D, J_2, true); - jumper_store(J_E, J_6, true); - jumper_store(J_F, J_8, true); - jumper_store(J_G, J_1, true); - jumper_store(J_H, J_3, true); - - pinMode(P_NASLAP, INPUT_PULLUP); - pinMode(P_RELAY_1, OUTPUT); - pinMode(P_RELAY_2, OUTPUT); - pinMode(P_LEDSTRIP, OUTPUT); - - Serial.begin(9600); - lcd.begin(); -} - -#define seconds_display(seconds) ((((seconds)/60)*100)+((seconds)%60)) - -// the loop function runs over and over again forever -void loop() { - Serial.println("Inicializace systemu..."); - - lcd.backlight(); - lcd.clear(); - lcd.print(" (c) SPOJE.NET"); - lcd.setCursor(0,1); - lcd.print("Tomas@MudrunkaCZ"); - - display.setBrightness(0x0f); - display.setColon(true); - display.showNumberDec(2323); - - delay(5000); - - lcd.noDisplay(); - lcd.noBacklight(); - display.setBrightness(0x00); - - display.setBrightness(0); - display.showNumberDec(0); - - analogWrite(P_LEDSTRIP, 0); - digitalWrite(P_RELAY_1, HIGH); - digitalWrite(P_RELAY_2, HIGH); - - sound(P_PIEZO, BEEP_FREQ, BEEP_LEN); - delay(BEEP_LEN); - sound(P_PIEZO, BEEP_FREQ, BEEP_LEN); - Serial.println("Cekam na aktivaci..."); - while(digitalRead(P_NASLAP)); - - Serial.println("Sekvence aktivovana!"); - - display.setBrightness(0x0f); - for(int i=0;i<70;i++) { - sound(P_PIEZO, random(500,10000), random(10,100)); - display.showNumberDec(random(1000,9999)); - analogWrite(P_LEDSTRIP, random(0,255)); - } - sound(P_PIEZO, BEEP_FREQ, 2000); - - Serial.println("Odpocet aktivovan!"); - int timer = TIMEOUT; - while(check_jumpers() != 8) { - Serial.print("Zbyva: "); - Serial.print(timer, DEC); - Serial.println(" sekund"); - if(timer <= 0) { - digitalWrite(P_RELAY_1, LOW); - } - display.setColon(timer%2); - display.showNumberDec(seconds_display(timer)); - analogWrite(P_LEDSTRIP, map(timer%5, 0, 4, 255, 10)); - digitalWrite(P_RELAY_2, timer%2); - if(timer>0) { - timer--; - sound(P_PIEZO, BEEP_FREQ, BEEP_LEN); - delay(1000-BEEP_LEN); - } else { - analogWrite(P_LEDSTRIP, random(0,255)); - sound(P_PIEZO, random(500,10000), random(100,1000)); - } - } - - Serial.println("Odpocet zastaven."); - display.setColon(true); - display.showNumberDec(seconds_display(timer)); - analogWrite(P_LEDSTRIP, 0); - digitalWrite(P_RELAY_1, HIGH); - - //Muhammad Ismáil Árifi - lcd.clear(); - lcd.print(" Muhammad"); - lcd.setCursor(0,1); - lcd.print(" Ismail Arifi"); - lcd.backlight(); - lcd.display(); - - Serial.println("Cekam na reset..."); - //while(digitalRead(P_NASLAP)); - while(check_jumpers() != 0) delay(1000); -}