Commit | Line | Data |
---|---|---|
e6e13bcc TM |
1 | /* |
2 | */ | |
3 | ||
4 | //Nastaveni bomby | |
5 | ||
6 | #define TIME_COUNTDOWN 600 | |
7 | ||
8 | ||
9 | //Prirazeni pinu | |
10 | ||
11 | #define PIN_CABLE_CHECK 2 | |
12 | ||
13 | #define PIN_KEY_CLK 3 //IRQ! | |
14 | #define PIN_KEY_DATA 4 | |
15 | ||
16 | #define PIN_LED_R 5 | |
17 | #define PIN_LED_G 6 | |
18 | #define PIN_LED_B 7 | |
19 | ||
20 | #define PIN_COIL_LO 10 | |
21 | #define PIN_COIL_HI 11 | |
22 | ||
23 | #define ADDR_DISPLAY 0x70 | |
24 | ||
25 | ////////////////////////////////////////////////////////////////// | |
26 | ||
27 | #include <PS2Keyboard.h> | |
28 | ||
29 | //#include <Wire.h> // Enable this line if using Arduino Uno, Mega, etc. | |
30 | #include <Adafruit_GFX.h> | |
31 | #include "Adafruit_LEDBackpack.h" | |
32 | ||
33 | PS2Keyboard keyboard; | |
34 | Adafruit_7segment display = Adafruit_7segment(); | |
35 | ||
36 | void setup() { | |
37 | Serial.begin(9600); | |
38 | Serial.println("Keyboard Test:"); | |
39 | ||
40 | keyboard.begin(PIN_KEY_DATA, PIN_KEY_CLK); | |
41 | ||
42 | display.begin(ADDR_DISPLAY); | |
43 | display.clear(); | |
44 | //display.writeDisplay(); | |
45 | ||
46 | pinMode(PIN_LED_R, OUTPUT); | |
47 | pinMode(PIN_LED_G, OUTPUT); | |
48 | pinMode(PIN_LED_B, OUTPUT); | |
49 | pinMode(PIN_COIL_LO, OUTPUT); | |
50 | pinMode(PIN_COIL_HI, OUTPUT); | |
51 | pinMode(PIN_CABLE_CHECK, INPUT_PULLUP); | |
52 | } | |
53 | ||
54 | void loop() { | |
55 | if (keyboard.available()) { | |
56 | ||
57 | // read the next key | |
58 | char c = keyboard.read(); | |
59 | ||
60 | // check for some of the special keys | |
61 | if (c == PS2_ENTER) { | |
62 | Serial.println(); | |
63 | } else { | |
64 | Serial.print(c); | |
65 | } | |
66 | ||
67 | if(digitalRead(PIN_CABLE_CHECK)) c+=16; | |
68 | display.print(c, HEX); | |
69 | display.drawColon(c%2); | |
70 | //display.setBrightness(random(0,15)); | |
71 | display.setBrightness(0); | |
72 | //display.clear(); | |
73 | display.writeDisplay(); | |
74 | ||
75 | ||
76 | if(c%2) { | |
77 | analogWrite(PIN_LED_R, random(0,255)); // turn the LED on (HIGH is the voltage level) | |
78 | analogWrite(PIN_LED_G, random(0,255)); // turn the LED on (HIGH is the voltage level) | |
79 | analogWrite(PIN_LED_B, random(0,255)); // turn the LED on (HIGH is the voltage level) | |
80 | digitalWrite(PIN_COIL_HI, HIGH); // turn the LED on (HIGH is the voltage level) | |
81 | } else { | |
82 | digitalWrite(PIN_COIL_LO, HIGH); // turn the LED on (HIGH is the voltage level) | |
83 | digitalWrite(PIN_LED_R, LOW); // turn the LED on (HIGH is the voltage level) | |
84 | digitalWrite(PIN_LED_G, LOW); // turn the LED on (HIGH is the voltage level) | |
85 | digitalWrite(PIN_LED_B, LOW); // turn the LED on (HIGH is the voltage level) | |
86 | } | |
87 | delay(random(1,15)); // wait for a second | |
88 | digitalWrite(PIN_COIL_LO, LOW); // turn the LED off by making the voltage LOW | |
89 | digitalWrite(PIN_COIL_HI, LOW); // turn the LED off by making the voltage LOW | |
90 | ||
91 | if(c == '.') { | |
92 | int d = random(100,1000); | |
93 | for(int i = 0; i < 1000; i++) { | |
94 | ||
95 | digitalWrite(PIN_COIL_LO, HIGH); //digitalWrite(11, HIGH); | |
96 | delayMicroseconds(d/2); | |
97 | digitalWrite(PIN_COIL_LO, LOW); //digitalWrite(11, LOW); | |
98 | delayMicroseconds(d/2); | |
99 | } | |
100 | } | |
101 | } | |
102 | ||
103 | ||
104 | } |