From: Tomas Mudrunka Date: Wed, 6 Nov 2019 11:47:05 +0000 (+0100) Subject: klavesnice pro unikovku X-Git-Url: https://git.harvie.cz/?a=commitdiff_plain;h=e6e13bcc33fa6040a7f00159516482dd3a6273be;p=mirrors%2FPrograms.git klavesnice pro unikovku --- diff --git a/arduino/bomba-keypad/bomba-keypad.ino b/arduino/bomba-keypad/bomba-keypad.ino index 3221e78..179d432 100644 --- a/arduino/bomba-keypad/bomba-keypad.ino +++ b/arduino/bomba-keypad/bomba-keypad.ino @@ -2,10 +2,16 @@ * 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 @@ -85,9 +91,13 @@ void setup(){ intro(); cleardisp('_'); drawdisp(0); - + +#ifndef SOFTSERIAL // send the keyboard start up keyboard.keyboard_init(); +#else + mySerial.begin(4800); +#endif Serial.begin(9600); @@ -98,11 +108,13 @@ void setup(){ 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(); @@ -112,8 +124,12 @@ void loop(){ 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 @@ -126,7 +142,9 @@ void loop(){ if (customKey == '*') { //Send PS2 +#ifndef SOFTSERIAL keyboard.keyboard_mkbrk(scancodes[10]); +#endif //analogWrite(keyledPin, 0); outro(); @@ -136,6 +154,8 @@ void loop(){ } 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 new file mode 100644 index 0000000..f0f9f7a --- /dev/null +++ b/arduino/bomba-ledtest/bomba-ledtest.ino @@ -0,0 +1,68 @@ +#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 new file mode 100644 index 0000000..57160a3 --- /dev/null +++ b/arduino/bomba-ps2test/bomba-ps2test.ino @@ -0,0 +1,26 @@ +#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 new file mode 100644 index 0000000..b104cc7 --- /dev/null +++ b/arduino/bomba2/bomba2.ino/bomba2.ino.ino @@ -0,0 +1,104 @@ +/* +*/ + +//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 new file mode 100644 index 0000000..b104cc7 --- /dev/null +++ b/arduino/bomba2/bomba2b/bomba2b.ino @@ -0,0 +1,104 @@ +/* +*/ + +//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 new file mode 100644 index 0000000..5c49c1c --- /dev/null +++ b/arduino/bomba2b/bomba2b.ino @@ -0,0 +1,219 @@ +/* + * 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 new file mode 100644 index 0000000..68e420b --- /dev/null +++ b/arduino/exit-rum-display/exit-rum-display.ino @@ -0,0 +1,44 @@ +#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 new file mode 100644 index 0000000..bffa260 --- /dev/null +++ b/arduino/exit-rum/exit-rum.ino @@ -0,0 +1,197 @@ +/* + * 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); +} diff --git a/arduino/ps2_keyboard_test/ps2_keyboard_test.ino b/arduino/ps2_keyboard_test/ps2_keyboard_test.ino new file mode 100644 index 0000000..88bd283 --- /dev/null +++ b/arduino/ps2_keyboard_test/ps2_keyboard_test.ino @@ -0,0 +1,108 @@ +//Source: http://dduino.blogspot.com/2011/11/arduino-ps2-emulator-computer-control.html + +//KBD stuff +#include "ps2dev.h" // to emulate a PS/2 device +PS2dev keyboard(19,18); // PS2dev object (2:data, 3:clock) +int enabled = 0; // pseudo variable for state of "keyboard" +unsigned char c; //char stores data recieved from computer for KBD + +//Sonar stuff + +void ack() +{ + //acknowledge commands + while(keyboard.write(0xFA)); +} + +int keyboardcommand(int command) +{ + unsigned char val; + switch (command) + { + case 0xFF: //reset + ack(); + //the while loop lets us wait for the host to be ready + while(keyboard.write(0xAA)!=0); + break; + case 0xFE: //resend + ack(); + break; + case 0xF6: //set defaults + //enter stream mode + ack(); + break; + case 0xF5: //disable data reporting + //FM + enabled = 0; + ack(); + break; + case 0xF4: //enable data reporting + //FM + enabled = 1; + ack(); + break; + case 0xF3: //set typematic rate + ack(); + keyboard.read(&val); //do nothing with the rate + ack(); + break; + case 0xF2: //get device id + ack(); + keyboard.write(0xAB); + keyboard.write(0x83); + break; + case 0xF0: //set scan code set + ack(); + keyboard.read(&val); //do nothing with the rate + ack(); + break; + case 0xEE: //echo + //ack(); + keyboard.write(0xEE); + break; + case 0xED: //set/reset LEDs + ack(); + keyboard.read(&val); //do nothing with the rate + Serial.print("LEDs: "); + Serial.println(val, HEX); + digitalWrite(LED_BUILTIN, val); + ack(); + break; + } + return 0; +} + +void setup() +{ + // send the keyboard start up + while(keyboard.write(0xAA)!=0); + delay(10); + // initialize the serial port: + Serial.begin(9600); + pinMode(LED_BUILTIN, OUTPUT); +} + +void loop() +{ + //if host device wants to send a command: + if(keyboard.available()) + { + while(keyboard.read(&c)); + //delay(100); + keyboardcommand(c); + //delay(100); + //c = 0; + } + + + delay(1000); + + keyboard.write(0x16); + keyboard.write(0xF0); + keyboard.write(0x16); + Serial.print('.'); + + //delay(1000); + + +} diff --git a/arduino/ps2_keyboard_test2/ps2_keyboard_test2.ino b/arduino/ps2_keyboard_test2/ps2_keyboard_test2.ino new file mode 100644 index 0000000..b0841f4 --- /dev/null +++ b/arduino/ps2_keyboard_test2/ps2_keyboard_test2.ino @@ -0,0 +1,28 @@ +#include // to emulate a PS/2 device +PS2dev keyboard(19,18); // PS2dev object (3:clock, 2:data) +unsigned long timecount = 0; + +void setup() +{ + keyboard.keyboard_init(); + Serial.begin(9600); + pinMode(LED_BUILTIN, OUTPUT); +} + +void loop() +{ + //Handle PS2 communication and react to keyboard led change + unsigned char leds; + if(keyboard.keyboard_handle(&leds)) { + //Serial.print('LEDS'); + //Serial.print(leds, HEX); + digitalWrite(LED_BUILTIN, leds); + } + + //Print letter every second + if((millis() - timecount) > 1000) { + keyboard.keyboard_mkbrk(0x16); + Serial.print('.'); + timecount = millis(); + } +}