├── Arduino ├── .DS_Store ├── AT_commands │ └── AT_commands.ino ├── All_Sensors │ └── All_Sensors.ino ├── Project_04_Battery_Monitor │ └── Project_04_Battery_Monitor.ino ├── Project_06_PIR_Alarm │ └── Project_06_PIR_Alarm.ino ├── Project_06_PIR_Alarm_No_Batt │ └── Project_06_PIR_Alarm_No_Batt.ino ├── Project_10_Door_Sensor │ └── Project_10_Door_Sensor.ino ├── Project_11_Smoke_alarm │ └── Project_11_Smoke_alarm.ino ├── Project_12_Temperature │ └── Project_12_Temperature.ino ├── Project_13_Control_Center_USB │ └── Project_13_Control_Center_USB.ino ├── Project_15_Flasher │ ├── .DS_Store │ └── Project_15_Flasher.ino ├── Project_16_Sound_Movement │ └── Project_16_Sound_Movement.ino ├── Project_16_Sounder_Test │ ├── Project_16_sounder_test.ino │ └── Project_16_sounder_test │ │ └── Project_16_sounder_test.ino ├── Project_18_Scanner │ └── Project_18_Scanner.ino ├── Project_19_Morse_Beacon │ ├── EEPROMAnything.h │ └── Project_19_Morse_Beacon.ino ├── Project_20_Haptic_Communicator_Test │ └── Project_20_Haptic_Communicator_Test.ino └── Project_20_haptic_communicator │ └── Project_20_haptic_communicator.ino ├── LICENSE ├── README.md ├── Raspberry Pi ├── .DS_Store ├── control_center_bt │ └── control.py ├── control_center_usb │ └── control.py └── usb_webcam │ ├── monitor.py │ └── test.py └── mylist.pickle /Arduino/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonmonk/zombies/424ea622e71f16947dc00f2fde673dfa2508eeb6/Arduino/.DS_Store -------------------------------------------------------------------------------- /Arduino/AT_commands/AT_commands.ino: -------------------------------------------------------------------------------- 1 | #include 2 | SoftwareSerial mySerial(4, 2); // RX, TX 3 | 4 | String command = ""; // Stores response of the HC-06 Bluetooth device 5 | 6 | 7 | void setup() { 8 | // Open serial communications: 9 | Serial.begin(9600); 10 | Serial.println("Type AT commands!"); 11 | 12 | // The HC-06 defaults to 9600 according to the datasheet. 13 | mySerial.begin(9600); 14 | } 15 | 16 | void loop() { 17 | // Read device output if available. 18 | if (mySerial.available()) { 19 | while(mySerial.available()) { // While there is more to be read, keep reading. 20 | command += (char)mySerial.read(); 21 | } 22 | 23 | Serial.println(command); 24 | command = ""; // No repeats 25 | } 26 | 27 | // Read user input if available. 28 | if (Serial.available()){ 29 | delay(10); // The delay is necessary to get this working! 30 | mySerial.write(Serial.read()); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Arduino/All_Sensors/All_Sensors.ino: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include 4 | 5 | /* 6 | Any projects that you want to exclude from this program should have a 7 | value of "false". That way, you will not get any false alarms because 8 | of missing hardware. 9 | */ 10 | const boolean project4 = true; // Battery Monitor 11 | const boolean project6 = true; // PIR Alarm 12 | const boolean project10 = true; // Door Monitor 13 | const boolean project11 = true; // Fire Alarm 14 | const boolean project12 = true; // Temperature Monitor 15 | 16 | // Pin allocations 17 | const int buzzerPin = 11; 18 | const int voltagePin = A3; 19 | const int backlightPin = 10; 20 | const int switchPin = A0; 21 | const int pirPin = 2; 22 | const int doorPin = 12; 23 | const int smokePin = 3; 24 | const int tempPin = A2; 25 | 26 | 27 | // Project 2 constants 28 | const float maxV = 12.6; 29 | const float minV = 11.7; 30 | const float warnV = 11.7; 31 | const float R1 = 470.0; 32 | const float R2 = 270.0; 33 | const float k = (R1 + R2) / R2; 34 | 35 | // Project 12 constants 36 | // these can be in C or F 37 | const float maxTemp = 45.0; 38 | const float minTemp = -10.0; 39 | 40 | 41 | // RS,E,D4,D5,D6,D7 42 | LiquidCrystal lcd(8, 9, 4, 5, 6, 7); 43 | 44 | boolean mute = false; 45 | 46 | void setup() 47 | { 48 | // This because of a defect in common cheap LCD displays 49 | // backlight controlled by transistor D10 high can 50 | // burn out Arduino pin 51 | pinMode(backlightPin, INPUT); 52 | pinMode(pirPin, INPUT); 53 | pinMode(smokePin, INPUT); 54 | pinMode(doorPin, INPUT_PULLUP); 55 | lcd.begin(16, 2); 56 | } 57 | 58 | void loop() 59 | { 60 | if (project4) checkBattery(); 61 | if (project6) checkPIR(); 62 | if (project10) checkDoor(); 63 | if (project11) checkSmoke(); 64 | if (project12) checkTemp(); 65 | 66 | if (analogRead(switchPin) < 1000) // any key pressed 67 | { 68 | mute = ! mute; 69 | if (mute) 70 | { 71 | noTone(buzzerPin); 72 | lcd.setCursor(12, 1); 73 | lcd.print("MUTE"); 74 | } 75 | else 76 | { 77 | lcd.setCursor(12, 1); 78 | lcd.print(" "); 79 | } 80 | delay(300); 81 | } 82 | delay(100); 83 | } 84 | 85 | void alarm(char message[]) 86 | { 87 | lcd.setCursor(0, 1); 88 | lcd.print(message); 89 | delay(100); 90 | lcd.setCursor(0, 1); 91 | lcd.print(" "); 92 | if (!mute) 93 | { 94 | tone(buzzerPin, 1000); 95 | } 96 | delay(100); 97 | } 98 | 99 | 100 | void alarm(char message[], float value) 101 | { 102 | alarm(message); 103 | lcd.setCursor(5, 1); 104 | lcd.print(" "); 105 | lcd.print(value); 106 | } 107 | 108 | void warn(char message[]) 109 | { 110 | lcd.setCursor(0, 1); 111 | lcd.print(message); 112 | delay(100); 113 | lcd.setCursor(0, 1); 114 | lcd.print(" "); 115 | if (!mute) 116 | { 117 | tone(buzzerPin, 1000); 118 | delay(100); 119 | noTone(buzzerPin); 120 | } 121 | delay(100); 122 | } 123 | 124 | 125 | void checkBattery() 126 | { 127 | if (readVoltage() < warnV) 128 | { 129 | alarm("VOLTS!!"); 130 | } 131 | displayVoltage(); 132 | displayBar(); 133 | } 134 | 135 | 136 | void displayVoltage() 137 | { 138 | lcd.setCursor(0, 0); 139 | lcd.print("Battery"); 140 | lcd.setCursor(8, 0); 141 | lcd.print(" "); 142 | lcd.setCursor(8, 0); 143 | lcd.print(readVoltage()); 144 | lcd.setCursor(14, 0); 145 | lcd.print("V"); 146 | } 147 | 148 | float readVoltage() 149 | { 150 | int raw = analogRead(voltagePin); 151 | float vout = (float(raw) / 1023.0) * 5.0; 152 | float vin = (vout * k); 153 | return vin; 154 | } 155 | 156 | void displayBar() 157 | { 158 | float v = readVoltage(); 159 | float range = maxV - minV; 160 | float fullness = (v - minV) / range; 161 | 162 | int numBars = fullness * 10; 163 | lcd.setCursor(0, 1); 164 | for (int i = 0; i < 10; i++) 165 | { 166 | if (numBars > i) 167 | { 168 | lcd.print("*"); 169 | } 170 | else 171 | { 172 | lcd.print(" "); 173 | } 174 | } 175 | } 176 | 177 | 178 | void checkPIR() 179 | { 180 | if (digitalRead(pirPin)) 181 | { 182 | alarm("ZOMBIES!!"); 183 | } 184 | } 185 | 186 | void checkDoor() 187 | { 188 | if (digitalRead(doorPin)) 189 | { 190 | warn("DOOR"); 191 | } 192 | } 193 | 194 | void checkSmoke() 195 | { 196 | if (digitalRead(smokePin)) 197 | { 198 | alarm("FIRE!!"); 199 | } 200 | } 201 | 202 | 203 | void checkTemp() 204 | { 205 | float t = readTemp(); 206 | if (t > maxTemp) 207 | { 208 | alarm("HOT", t); 209 | } 210 | else if (t < minTemp) 211 | { 212 | alarm("COLD", t); 213 | } 214 | } 215 | 216 | float readTemp() 217 | { 218 | int raw = analogRead(tempPin); 219 | float volts = raw / 205.0; 220 | float tempC = 100.0 * volts - 50; 221 | float tempF = tempC * 9.0 / 5.0 + 32.0; 222 | // One of the following two lines must be uncommented 223 | // Either return the temperature in C or F 224 | return tempC; 225 | // return tempF; 226 | } 227 | -------------------------------------------------------------------------------- /Arduino/Project_04_Battery_Monitor/Project_04_Battery_Monitor.ino: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include 4 | 5 | // Project 2 thresholds 6 | const float maxV = 12.6; 7 | const float minV = 11.7; 8 | const float warnV = 11.7; 9 | 10 | // Pin allocations 11 | const int buzzerPin = 11; 12 | const int voltagePin = A3; 13 | const int backlightPin = 10; 14 | const int switchPin = A0; 15 | 16 | // Project 2 constants 17 | const float R1 = 470.0; 18 | const float R2 = 270.0; 19 | const float k = (R1 + R2) / R2; 20 | 21 | 22 | // RS,E,D4,D5,D6,D7 23 | LiquidCrystal lcd(8, 9, 4, 5, 6, 7); 24 | 25 | boolean mute = false; 26 | 27 | void setup() 28 | { 29 | // Because of a defect in common cheap LCD displays, 30 | // backlight controlled by transistor D10 high can 31 | // burn out Arduino pin 32 | pinMode(backlightPin, INPUT); 33 | lcd.begin(16, 2); 34 | lcd.setCursor(0, 0); 35 | lcd.print("Battery "); 36 | } 37 | 38 | void loop() 39 | { 40 | displayVoltage(); 41 | displayBar(); 42 | if (readVoltage() < warnV && ! mute) 43 | { 44 | tone(buzzerPin, 1000); 45 | } 46 | if (analogRead(switchPin) < 1000) // any key pressed 47 | { 48 | mute = ! mute; 49 | if (mute) noTone(buzzerPin); 50 | delay(300); 51 | } 52 | delay(100); 53 | } 54 | 55 | void displayVoltage() 56 | { 57 | lcd.setCursor(8, 0); 58 | lcd.print(" "); 59 | lcd.setCursor(8, 0); 60 | lcd.print(readVoltage()); 61 | lcd.setCursor(14, 0); 62 | lcd.print("V"); 63 | } 64 | 65 | 66 | float readVoltage() 67 | { 68 | int raw = analogRead(voltagePin); 69 | float vout = (float(raw) / 1023.0) * 5.0; 70 | float vin = (vout * k); 71 | return vin; 72 | } 73 | 74 | void displayBar() 75 | { 76 | float v = readVoltage(); 77 | float range = maxV - minV; 78 | float fullness = (v - minV) / range; 79 | int numBars = fullness * 16; 80 | lcd.setCursor(0, 1); 81 | for (int i = 0; i < 16; i++) 82 | { 83 | if (numBars > i) 84 | { 85 | lcd.print("*"); 86 | } 87 | else 88 | { 89 | lcd.print(" "); 90 | } 91 | } 92 | if (mute) 93 | { 94 | lcd.setCursor(12, 1); 95 | lcd.print("MUTE"); 96 | } 97 | } 98 | 99 | 100 | -------------------------------------------------------------------------------- /Arduino/Project_06_PIR_Alarm/Project_06_PIR_Alarm.ino: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include 4 | 5 | 6 | // Pin allocations 7 | const int buzzerPin = 11; 8 | const int backlightPin = 10; 9 | const int switchPin = A0; 10 | const int pirPin = 2; 11 | 12 | // RS,E,D4,D5,D6,D7 13 | LiquidCrystal lcd(8, 9, 4, 5, 6, 7); 14 | 15 | boolean mute = false; 16 | 17 | void setup() 18 | { 19 | // This because of a defect in common cheap LCD displays 20 | // backlight controlled by transistor D10 high can 21 | // burn out Arduino pin 22 | pinMode(backlightPin, INPUT); 23 | pinMode(pirPin, INPUT); 24 | lcd.begin(16, 2); 25 | } 26 | 27 | void loop() 28 | { 29 | 30 | checkPIR(); 31 | 32 | if (analogRead(switchPin) < 1000) // any key pressed 33 | { 34 | mute = ! mute; 35 | if (mute) 36 | { 37 | noTone(buzzerPin); 38 | lcd.setCursor(12, 1); 39 | lcd.print("MUTE"); 40 | } 41 | else 42 | { 43 | lcd.setCursor(12, 1); 44 | lcd.print(" "); 45 | } 46 | delay(300); 47 | } 48 | delay(100); 49 | } 50 | 51 | void alarm(char message[]) 52 | { 53 | lcd.setCursor(0, 1); 54 | lcd.print(message); 55 | delay(100); 56 | lcd.setCursor(0, 1); 57 | lcd.print(" "); 58 | if (!mute) 59 | { 60 | tone(buzzerPin, 1000); 61 | } 62 | delay(100); 63 | } 64 | 65 | 66 | void checkPIR() 67 | { 68 | if (digitalRead(pirPin)) 69 | { 70 | alarm("ZOMBIES!!"); 71 | } 72 | } 73 | 74 | -------------------------------------------------------------------------------- /Arduino/Project_06_PIR_Alarm_No_Batt/Project_06_PIR_Alarm_No_Batt.ino: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include 4 | 5 | 6 | const int buzzerPin = 11; 7 | const int backlightPin = 10; 8 | const int switchPin = A0; 9 | const int pirPin = 2; 10 | 11 | 12 | // RS,E,D4,D5,D6,D7 13 | LiquidCrystal lcd(8, 9, 4, 5, 6, 7); 14 | boolean silent = false; 15 | 16 | void setup() 17 | { 18 | // This because of a defect in common cheap LCD displays 19 | // backlight controlled by transistor D10 high can 20 | // burn out Arduino pin 21 | pinMode(backlightPin, INPUT); 22 | pinMode(pirPin, INPUT); 23 | } 24 | 25 | void loop() 26 | { 27 | checkPIR(); 28 | if (analogRead(switchPin) < 1000) // any key pressed 29 | { 30 | silent = ! silent; 31 | if (silent) noTone(buzzerPin); 32 | delay(300); 33 | } 34 | delay(100); 35 | } 36 | 37 | void checkPIR() 38 | { 39 | boolean zombies = digitalRead(pirPin); 40 | if (zombies) 41 | { 42 | if (! silent) 43 | { 44 | tone(buzzerPin, 1000); 45 | } 46 | lcd.setCursor(0, 1); 47 | lcd.print("ZOMBIES!!"); 48 | } 49 | else 50 | { 51 | lcd.setCursor(0, 1); 52 | lcd.print(" "); 53 | } 54 | if (silent) 55 | { 56 | lcd.setCursor(12, 0); 57 | lcd.print("MUTE"); 58 | } 59 | else 60 | { 61 | lcd.setCursor(12, 0); 62 | lcd.print(" "); 63 | } 64 | } 65 | 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /Arduino/Project_10_Door_Sensor/Project_10_Door_Sensor.ino: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include 4 | 5 | 6 | // Pin allocations 7 | const int buzzerPin = 11; 8 | const int backlightPin = 10; 9 | const int switchPin = A0; 10 | const int doorPin = 12; 11 | 12 | // RS,E,D4,D5,D6,D7 13 | LiquidCrystal lcd(8, 9, 4, 5, 6, 7); 14 | 15 | boolean mute = false; 16 | 17 | void setup() 18 | { 19 | // This because of a defect in common cheap LCD displays 20 | // backlight controlled by transistor D10 high can 21 | // burn out Arduino pin 22 | pinMode(backlightPin, INPUT); 23 | pinMode(doorPin, INPUT_PULLUP); 24 | lcd.begin(16, 2); 25 | } 26 | 27 | void loop() 28 | { 29 | checkDoor(); 30 | 31 | if (analogRead(switchPin) < 1000) // any key pressed 32 | { 33 | mute = ! mute; 34 | if (mute) 35 | { 36 | noTone(buzzerPin); 37 | lcd.setCursor(12, 1); 38 | lcd.print("MUTE"); 39 | } 40 | else 41 | { 42 | lcd.setCursor(12, 1); 43 | lcd.print(" "); 44 | } 45 | delay(300); 46 | } 47 | delay(100); 48 | } 49 | 50 | void warn(char message[]) 51 | { 52 | lcd.setCursor(0, 1); 53 | lcd.print(message); 54 | delay(100); 55 | lcd.setCursor(0, 1); 56 | lcd.print(" "); 57 | if (!mute) 58 | { 59 | tone(buzzerPin, 1000); 60 | delay(100); 61 | noTone(buzzerPin); 62 | } 63 | delay(100); 64 | } 65 | 66 | void checkDoor() 67 | { 68 | if (digitalRead(doorPin)) 69 | { 70 | warn("DOOR"); 71 | } 72 | } 73 | 74 | -------------------------------------------------------------------------------- /Arduino/Project_11_Smoke_alarm/Project_11_Smoke_alarm.ino: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include 4 | 5 | const boolean project11 = true; // Fire Alarm 6 | 7 | // Pin allocations 8 | const int buzzerPin = 11; 9 | const int backlightPin = 10; 10 | const int switchPin = A0; 11 | const int smokePin = 3; 12 | 13 | 14 | // RS,E,D4,D5,D6,D7 15 | LiquidCrystal lcd(8, 9, 4, 5, 6, 7); 16 | 17 | boolean mute = false; 18 | 19 | void setup() 20 | { 21 | // This because of a defect in common cheap LCD displays 22 | // backlight controlled by transistor D10 high can 23 | // burn out Arduino pin 24 | pinMode(backlightPin, INPUT); 25 | pinMode(smokePin, INPUT); 26 | lcd.begin(16, 2); 27 | } 28 | 29 | void loop() 30 | { 31 | checkSmoke(); 32 | 33 | if (analogRead(switchPin) < 1000) // any key pressed 34 | { 35 | mute = ! mute; 36 | if (mute) 37 | { 38 | noTone(buzzerPin); 39 | lcd.setCursor(12, 1); 40 | lcd.print("MUTE"); 41 | } 42 | else 43 | { 44 | lcd.setCursor(12, 1); 45 | lcd.print(" "); 46 | } 47 | delay(300); 48 | } 49 | delay(100); 50 | } 51 | 52 | void alarm(char message[]) 53 | { 54 | lcd.setCursor(0, 1); 55 | lcd.print(message); 56 | delay(100); 57 | lcd.setCursor(0, 1); 58 | lcd.print(" "); 59 | if (!mute) 60 | { 61 | tone(buzzerPin, 1000); 62 | } 63 | delay(100); 64 | } 65 | 66 | 67 | void checkSmoke() 68 | { 69 | if (digitalRead(smokePin)) 70 | { 71 | alarm("FIRE!!"); 72 | } 73 | } 74 | 75 | 76 | -------------------------------------------------------------------------------- /Arduino/Project_12_Temperature/Project_12_Temperature.ino: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include 4 | 5 | // Pin allocations 6 | const int buzzerPin = 11; 7 | const int backlightPin = 10; 8 | const int switchPin = A0; 9 | const int tempPin = A2; 10 | 11 | // Project 12 constants 12 | // these can be in C or F 13 | const float maxTemp = 45.0; 14 | const float minTemp = -10.0; 15 | 16 | 17 | // RS,E,D4,D5,D6,D7 18 | LiquidCrystal lcd(8, 9, 4, 5, 6, 7); 19 | 20 | boolean mute = false; 21 | 22 | void setup() 23 | { 24 | // This because of a defect in common cheap LCD displays 25 | // backlight controlled by transistor D10 high can 26 | // burn out Arduino pin 27 | pinMode(backlightPin, INPUT); 28 | lcd.begin(16, 2); 29 | } 30 | 31 | void loop() 32 | { 33 | checkTemp(); 34 | 35 | if (analogRead(switchPin) < 1000) // any key pressed 36 | { 37 | mute = ! mute; 38 | if (mute) 39 | { 40 | noTone(buzzerPin); 41 | lcd.setCursor(12, 1); 42 | lcd.print("MUTE"); 43 | } 44 | else 45 | { 46 | lcd.setCursor(12, 1); 47 | lcd.print(" "); 48 | } 49 | delay(300); 50 | } 51 | delay(100); 52 | } 53 | 54 | void alarm(char message[]) 55 | { 56 | lcd.setCursor(0, 1); 57 | lcd.print(message); 58 | delay(100); 59 | lcd.setCursor(0, 1); 60 | lcd.print(" "); 61 | if (!mute) 62 | { 63 | tone(buzzerPin, 1000); 64 | } 65 | delay(100); 66 | } 67 | 68 | void alarm(char message[], float value) 69 | { 70 | alarm(message); 71 | lcd.setCursor(5, 1); 72 | lcd.print(" "); 73 | lcd.print(value); 74 | } 75 | 76 | void checkTemp() 77 | { 78 | float t = readTemp(); 79 | if (t > maxTemp) 80 | { 81 | alarm("HOT", t); 82 | } 83 | else if (t < minTemp) 84 | { 85 | alarm("COLD", t); 86 | } 87 | } 88 | 89 | float readTemp() 90 | { 91 | int raw = analogRead(tempPin); 92 | float volts = raw / 205.0; 93 | float tempC = 100.0 * volts - 50; 94 | float tempF = tempC * 9.0 / 5.0 + 32.0; 95 | // One of the following two lines must be uncommented 96 | // Either return the temperature in C or F 97 | return tempC; 98 | // return tempF; 99 | } 100 | -------------------------------------------------------------------------------- /Arduino/Project_13_Control_Center_USB/Project_13_Control_Center_USB.ino: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include 4 | 5 | /* 6 | Any projects that you want to exclude from this program should have a 7 | value of "false". That way, you will not get any false alarms because 8 | of missing hardware. 9 | */ 10 | const boolean project2 = true; // Battery Monitor 11 | const boolean project6 = true; // PIR Alarm 12 | const boolean project10 = true; // Door Monitor 13 | const boolean project11 = true; // Fire Alarm 14 | const boolean project12 = true; // Temperature Monitor 15 | 16 | // Pin allocations 17 | const int buzzerPin = 11; 18 | const int voltagePin = A3; 19 | const int backlightPin = 10; 20 | const int switchPin = A0; 21 | const int pirPin = 2; 22 | const int doorPin = 12; 23 | const int smokePin = 3; 24 | const int tempPin = A2; 25 | 26 | 27 | // Project 2 constants 28 | const float maxV = 12.6; 29 | const float minV = 11.7; 30 | const float warnV = 11.7; 31 | const float R1 = 470.0; 32 | const float R2 = 270.0; 33 | const float k = (R1 + R2) / R2; 34 | 35 | // Project 12 constants 36 | // these can be in C or F 37 | const float maxTemp = 45.0; 38 | const float minTemp = -10.0; 39 | 40 | 41 | // RS,E,D4,D5,D6,D7 42 | LiquidCrystal lcd(8, 9, 4, 5, 6, 7); 43 | 44 | boolean mute = false; 45 | 46 | void setup() 47 | { 48 | // This because of a defect in common cheap LCD displays 49 | // backlight controlled by transistor D10 high can 50 | // burn out Arduino pin 51 | pinMode(backlightPin, INPUT); 52 | pinMode(pirPin, INPUT); 53 | pinMode(smokePin, INPUT); 54 | pinMode(doorPin, INPUT_PULLUP); 55 | lcd.begin(16, 2); 56 | Serial.begin(9600); 57 | } 58 | 59 | void loop() 60 | { 61 | if (Serial.available() && Serial.read() == '?') 62 | { 63 | reportStatus(); 64 | } 65 | 66 | if (project2) checkBattery(); 67 | if (project6) checkPIR(); 68 | if (project10) checkDoor(); 69 | if (project11) checkSmoke(); 70 | if (project12) checkTemp(); 71 | 72 | if (analogRead(switchPin) < 1000) // any key pressed 73 | { 74 | mute = ! mute; 75 | if (mute) 76 | { 77 | noTone(buzzerPin); 78 | lcd.setCursor(12, 1); 79 | lcd.print("MUTE"); 80 | } 81 | else 82 | { 83 | lcd.setCursor(12, 1); 84 | lcd.print(" "); 85 | } 86 | delay(300); 87 | } 88 | delay(100); 89 | } 90 | 91 | void alarm(char message[]) 92 | { 93 | lcd.setCursor(0, 1); 94 | lcd.print(message); 95 | delay(100); 96 | lcd.setCursor(0, 1); 97 | lcd.print(" "); 98 | if (!mute) 99 | { 100 | tone(buzzerPin, 1000); 101 | } 102 | delay(100); 103 | } 104 | 105 | 106 | void alarm(char message[], float value) 107 | { 108 | alarm(message); 109 | lcd.setCursor(5, 1); 110 | lcd.print(" "); 111 | lcd.print(value); 112 | } 113 | 114 | void warn(char message[]) 115 | { 116 | lcd.setCursor(0, 1); 117 | lcd.print(message); 118 | delay(100); 119 | lcd.setCursor(0, 1); 120 | lcd.print(" "); 121 | if (!mute) 122 | { 123 | tone(buzzerPin, 1000); 124 | delay(100); 125 | noTone(buzzerPin); 126 | } 127 | delay(100); 128 | } 129 | 130 | 131 | void checkBattery() 132 | { 133 | if (readVoltage() < warnV) 134 | { 135 | alarm("VOLTS!!"); 136 | } 137 | displayVoltage(); 138 | displayBar(); 139 | } 140 | 141 | 142 | void displayVoltage() 143 | { 144 | lcd.setCursor(0, 0); 145 | lcd.print("Battery"); 146 | lcd.setCursor(8, 0); 147 | lcd.print(" "); 148 | lcd.setCursor(8, 0); 149 | lcd.print(readVoltage()); 150 | lcd.setCursor(14, 0); 151 | lcd.print("V"); 152 | } 153 | 154 | float readVoltage() 155 | { 156 | int raw = analogRead(voltagePin); 157 | float vout = (float(raw) / 1023.0) * 5.0; 158 | float vin = (vout * k); 159 | return vin; 160 | } 161 | 162 | void displayBar() 163 | { 164 | float v = readVoltage(); 165 | float range = maxV - minV; 166 | float fullness = (v - minV) / range; 167 | 168 | int numBars = fullness * 10; 169 | lcd.setCursor(0, 1); 170 | for (int i = 0; i < 10; i++) 171 | { 172 | if (numBars > i) 173 | { 174 | lcd.print("*"); 175 | } 176 | else 177 | { 178 | lcd.print(" "); 179 | } 180 | } 181 | } 182 | 183 | 184 | void checkPIR() 185 | { 186 | if (digitalRead(pirPin)) 187 | { 188 | alarm("ZOMBIES!!"); 189 | } 190 | } 191 | 192 | void checkDoor() 193 | { 194 | if (digitalRead(doorPin)) 195 | { 196 | warn("DOOR"); 197 | } 198 | } 199 | 200 | void checkSmoke() 201 | { 202 | if (digitalRead(smokePin)) 203 | { 204 | alarm("FIRE!!"); 205 | } 206 | } 207 | 208 | 209 | void checkTemp() 210 | { 211 | float t = readTemp(); 212 | if (t > maxTemp) 213 | { 214 | alarm("HOT", t); 215 | } 216 | else if (t < minTemp) 217 | { 218 | alarm("COLD", t); 219 | } 220 | } 221 | 222 | float readTemp() 223 | { 224 | int raw = analogRead(tempPin); 225 | float volts = raw / 205.0; 226 | float tempC = 100.0 * volts - 50; 227 | float tempF = tempC * 9.0 / 5.0 + 32.0; 228 | // One of the following two lines must be uncommented 229 | // Either return the temperature in C or F 230 | return tempC; 231 | // return tempF; 232 | } 233 | 234 | void reportStatus() 235 | { 236 | Serial.print(readVoltage()); 237 | Serial.print(" "); 238 | Serial.print(readTemp()); 239 | Serial.print(" "); 240 | Serial.print(digitalRead(doorPin)); 241 | Serial.print(" "); 242 | Serial.print(digitalRead(pirPin)); 243 | Serial.print(" "); 244 | Serial.println(digitalRead(smokePin)); 245 | } 246 | 247 | -------------------------------------------------------------------------------- /Arduino/Project_15_Flasher/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonmonk/zombies/424ea622e71f16947dc00f2fde673dfa2508eeb6/Arduino/Project_15_Flasher/.DS_Store -------------------------------------------------------------------------------- /Arduino/Project_15_Flasher/Project_15_Flasher.ino: -------------------------------------------------------------------------------- 1 | const int flashPins[] = {7, 6, 5}; 2 | 3 | const long overallDelay = 20; // seconds 4 | const long delayBetweenFlashes = 1; // seconds 5 | 6 | void setup() 7 | { 8 | pinMode(flashPins[0], OUTPUT); 9 | pinMode(flashPins[1], OUTPUT); 10 | pinMode(flashPins[2], OUTPUT); 11 | } 12 | 13 | void loop() 14 | { 15 | flashCircle(); 16 | delay(overallDelay * 1000); 17 | } 18 | 19 | void flashCircle() 20 | { 21 | for (int i = 0; i < 3; i++) 22 | { 23 | digitalWrite(flashPins[i], HIGH); 24 | delay(200); 25 | digitalWrite(flashPins[i], LOW); 26 | delay(delayBetweenFlashes * 1000); 27 | } 28 | } 29 | 30 | -------------------------------------------------------------------------------- /Arduino/Project_16_Sound_Movement/Project_16_Sound_Movement.ino: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | const int minServoAngle = 10; 4 | const int maxServoAngle = 170; 5 | const int stepPause = 5; 6 | 7 | const int sounderPinA = 8; 8 | const int sounderPinB = 9; 9 | const int servoPin = 10; 10 | 11 | const long f = 3800; // find f using Project_16_sounder_test 12 | 13 | Servo arm; 14 | 15 | void setup() 16 | { 17 | arm.attach(servoPin); 18 | pinMode(sounderPinA, OUTPUT); 19 | pinMode(sounderPinB, OUTPUT); 20 | } 21 | 22 | void loop() 23 | { 24 | wave(); 25 | wave(); 26 | makeNoise(); 27 | } 28 | 29 | void wave() 30 | { 31 | // wave vigously from left to right 32 | for (int angle = minServoAngle; angle < maxServoAngle; angle++) 33 | { 34 | arm.write(angle); 35 | delay(stepPause); 36 | } 37 | for (int angle = maxServoAngle; angle > minServoAngle; angle--) 38 | { 39 | arm.write(angle); 40 | delay(stepPause); 41 | } 42 | } 43 | 44 | void makeNoise() 45 | { 46 | for (int i = 0; i < 5; i++) 47 | { 48 | beep(500); 49 | delay(1000); 50 | } 51 | } 52 | 53 | 54 | void beep(long duration) 55 | { 56 | long sounderPeriodMicros = 500000l / f; 57 | long cycles = (duration * 1000) / sounderPeriodMicros / 2; 58 | for (int i = 0; i < cycles; i++) 59 | { 60 | digitalWrite(sounderPinA, HIGH); 61 | digitalWrite(sounderPinB, LOW); 62 | delayMicroseconds(sounderPeriodMicros); 63 | digitalWrite(sounderPinA, LOW); 64 | digitalWrite(sounderPinB, HIGH); 65 | delayMicroseconds(sounderPeriodMicros); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /Arduino/Project_16_Sounder_Test/Project_16_sounder_test.ino: -------------------------------------------------------------------------------- 1 | const int sounderPinA = 8; 2 | const int sounderPinB = 9; 3 | 4 | void setup() 5 | { 6 | pinMode(sounderPinA, OUTPUT); 7 | pinMode(sounderPinB, OUTPUT); 8 | Serial.begin(9600); 9 | Serial.println("Enter frequency in Hz"); 10 | } 11 | 12 | void loop() 13 | { 14 | if (Serial.available()) 15 | { 16 | long f = Serial.parseInt(); 17 | beep(f, 1000); 18 | } 19 | } 20 | 21 | void beep(long f, long duration) 22 | { 23 | long sounderPeriodMicros = 500000l / f; 24 | long cycles = (duration * 1000) / sounderPeriodMicros / 2; 25 | for (int i = 0; i < cycles; i++) 26 | { 27 | digitalWrite(sounderPinA, HIGH); 28 | digitalWrite(sounderPinB, LOW); 29 | delayMicroseconds(sounderPeriodMicros); 30 | digitalWrite(sounderPinA, LOW); 31 | digitalWrite(sounderPinB, HIGH); 32 | delayMicroseconds(sounderPeriodMicros); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Arduino/Project_16_Sounder_Test/Project_16_sounder_test/Project_16_sounder_test.ino: -------------------------------------------------------------------------------- 1 | const int sounderPinA = 8; 2 | const int sounderPinB = 9; 3 | 4 | void setup() 5 | { 6 | pinMode(sounderPinA, OUTPUT); 7 | pinMode(sounderPinB, OUTPUT); 8 | Serial.begin(9600); 9 | Serial.println("Enter frequency in Hz"); 10 | } 11 | 12 | void loop() 13 | { 14 | if (Serial.available()) 15 | { 16 | long f = Serial.parseInt(); 17 | beep(f, 1000); 18 | } 19 | } 20 | 21 | void beep(long f, long duration) 22 | { 23 | long sounderPeriodMicros = 500000l / f; 24 | long cycles = (duration * 1000) / sounderPeriodMicros / 2; 25 | for (int i = 0; i < cycles; i++) 26 | { 27 | digitalWrite(sounderPinA, HIGH); 28 | digitalWrite(sounderPinB, LOW); 29 | delayMicroseconds(sounderPeriodMicros); 30 | digitalWrite(sounderPinA, LOW); 31 | digitalWrite(sounderPinB, HIGH); 32 | delayMicroseconds(sounderPeriodMicros); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Arduino/Project_18_Scanner/Project_18_Scanner.ino: -------------------------------------------------------------------------------- 1 | 2 | const int scanPin = A0; 3 | const int resetPin = A1; 4 | const int pulseLength = 1000; 5 | const int period = 5000; 6 | const int numStations = 5; 7 | 8 | int count = 0; 9 | 10 | void setup() 11 | { 12 | pinMode(scanPin, INPUT); 13 | pinMode(resetPin, INPUT); 14 | } 15 | 16 | void loop() 17 | { 18 | delay(period); 19 | pinMode(scanPin, OUTPUT); 20 | digitalWrite(scanPin, HIGH); 21 | delay(pulseLength); 22 | pinMode(scanPin, INPUT); 23 | count ++; 24 | if (count == numStations) 25 | { 26 | count = 0; 27 | pinMode(resetPin, OUTPUT); 28 | digitalWrite(resetPin, HIGH); 29 | delay(pulseLength); 30 | pinMode(resetPin, INPUT); 31 | } 32 | } 33 | 34 | -------------------------------------------------------------------------------- /Arduino/Project_19_Morse_Beacon/EEPROMAnything.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include // for type definitions 3 | 4 | template int EEPROM_writeAnything(int ee, const T& value) 5 | { 6 | const byte* p = (const byte*)(const void*)&value; 7 | unsigned int i; 8 | for (i = 0; i < sizeof(value); i++) 9 | EEPROM.write(ee++, *p++); 10 | return i; 11 | } 12 | 13 | template int EEPROM_readAnything(int ee, T& value) 14 | { 15 | byte* p = (byte*)(void*)&value; 16 | unsigned int i; 17 | for (i = 0; i < sizeof(value); i++) 18 | *p++ = EEPROM.read(ee++); 19 | return i; 20 | } 21 | -------------------------------------------------------------------------------- /Arduino/Project_19_Morse_Beacon/Project_19_Morse_Beacon.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include "EEPROMAnything.h" 3 | 4 | const int ledPin = 13; 5 | int dotDelay = 100; // milliseconds 6 | const int gapBetweenRepeats = 10; // seconds 7 | const int maxMessageLen = 255; 8 | char message[maxMessageLen]; 9 | long lastFlashTime = 0; 10 | 11 | char* letters[] = { 12 | ".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", // A-I 13 | ".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.", // J-R 14 | "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--.." // S-Z 15 | }; 16 | 17 | char* numbers[] = {"-----", ".----", "..---", "...--", "....-", ".....", "-....", "--...", "---..", "----."}; 18 | 19 | void setup() 20 | { 21 | pinMode(ledPin, OUTPUT); 22 | Serial.begin(9600); 23 | Serial.println("Ready"); 24 | EEPROM_readAnything(0, message); 25 | if (! isalnum(message[0])) 26 | { 27 | strcpy(message, "SOS"); 28 | } 29 | flashMessage(); 30 | } 31 | 32 | void loop() 33 | { 34 | char ch; 35 | if (Serial.available()) // is there anything to be read from USB? 36 | { 37 | int n = Serial.readBytesUntil('\n', message, maxMessageLen-1); 38 | message[n] = '\0'; 39 | EEPROM_writeAnything(0, message); 40 | Serial.println(message); 41 | flashMessage(); 42 | } 43 | if (millis() > lastFlashTime + gapBetweenRepeats * 1000L) 44 | { 45 | flashMessage(); 46 | } 47 | } 48 | 49 | void flashMessage() 50 | { 51 | Serial.print("Sending: "); 52 | Serial.println(message); 53 | int i = 0; 54 | while (message[i] != '\0' && i < maxMessageLen) 55 | { 56 | if (Serial.available()) return; // new message 57 | char ch = message[i]; 58 | i++; 59 | if (ch >= 'a' && ch <= 'z') 60 | { 61 | flashSequence(letters[ch - 'a']); 62 | } 63 | else if (ch >= 'A' && ch <= 'Z') 64 | { 65 | flashSequence(letters[ch - 'A']); 66 | } 67 | else if (ch >= '0' && ch <= '9') 68 | { 69 | flashSequence(numbers[ch - '0']); 70 | } 71 | else if (ch == ' ') 72 | { 73 | delay(dotDelay * 4); // gap between words 74 | } 75 | } 76 | lastFlashTime = millis(); 77 | } 78 | 79 | void flashSequence(char* sequence) 80 | { 81 | int i = 0; 82 | while (sequence[i] != NULL) 83 | { 84 | flashDotOrDash(sequence[i]); 85 | i++; 86 | } 87 | delay(dotDelay * 3); // gap between letters 88 | } 89 | 90 | void flashDotOrDash(char dotOrDash) 91 | { 92 | digitalWrite(ledPin, HIGH); 93 | if (dotOrDash == '.') 94 | { 95 | delay(dotDelay); 96 | } 97 | else // must be a - 98 | { 99 | delay(dotDelay * 3); 100 | } 101 | digitalWrite(ledPin, LOW); 102 | delay(dotDelay); // gap between flashes 103 | } 104 | 105 | -------------------------------------------------------------------------------- /Arduino/Project_20_Haptic_Communicator_Test/Project_20_Haptic_Communicator_Test.ino: -------------------------------------------------------------------------------- 1 | 2 | const int buzzerPin = 5; 3 | const int switchPin = 2; 4 | 5 | const int V3 = 153; // analogWrite value for 3V 6 | 7 | 8 | void setup() 9 | { 10 | analogWrite(buzzerPin, 0); 11 | pinMode(switchPin, INPUT_PULLUP); 12 | Serial.begin(9600); 13 | Serial.println("HELLO"); 14 | } 15 | 16 | 17 | void loop() 18 | { 19 | if (digitalRead(switchPin) == LOW) 20 | { 21 | analogWrite(buzzerPin, V3); 22 | delay(100); 23 | analogWrite(buzzerPin, 0); 24 | } 25 | } 26 | 27 | -------------------------------------------------------------------------------- /Arduino/Project_20_haptic_communicator/Project_20_haptic_communicator.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | const int numberOfSends = 3; 6 | 7 | const int buzzerPin = 5; 8 | const int switchPin = 2; 9 | 10 | const int buzzerVolume = 100; // keep less that 153 for 3V 11 | const int buzzMinDuration = 20; 12 | 13 | byte data[] = {0x54, 0x12, 0x01, 0x00}; 14 | 15 | void setup() 16 | { 17 | analogWrite(buzzerPin, 0); 18 | pinMode(switchPin, INPUT_PULLUP); 19 | Serial.begin(9600); 20 | Serial.println("HELLO"); 21 | Mirf.spi = &MirfHardwareSpi; 22 | Mirf.init(); 23 | listenMode(); 24 | Mirf.payload = 4; 25 | Mirf.config(); 26 | } 27 | 28 | 29 | void loop() 30 | { 31 | if(!Mirf.isSending() && Mirf.dataReady()) 32 | { 33 | Serial.println("got somethinhg"); 34 | Mirf.getData(data); 35 | checkForBuzz(); 36 | } 37 | if (digitalRead(switchPin) == LOW) 38 | { 39 | Serial.println("Sending Buzz"); 40 | sendBuzz(); 41 | } 42 | } 43 | 44 | void listenMode() 45 | { 46 | Mirf.setRADDR((byte *)"serv1"); 47 | Serial.println("Listening"); 48 | } 49 | 50 | void sendMode() 51 | { 52 | Serial.println("Send mode"); 53 | 54 | } 55 | 56 | 57 | void sendBuzz() 58 | { 59 | sendMode(); 60 | for (int i = 0; i < numberOfSends; i++) 61 | { 62 | Mirf.setTADDR((byte *)"serv1"); 63 | Mirf.send(data); 64 | while(Mirf.isSending()){} 65 | } 66 | listenMode(); 67 | } 68 | 69 | 70 | void checkForBuzz() 71 | { 72 | if (data[0]==0x54 && data[1]==0x12 && data[2]==0x01) 73 | { 74 | analogWrite(buzzerPin, buzzerVolume); 75 | delay(buzzMinDuration); 76 | analogWrite(buzzerPin, 0); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Simon Monk 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # zombies 2 | 3 | Code to accompany the book [The Maker's Guide to Surviving the Zombie Apocalypse](https://www.nostarch.com/zombies) by [Simon Monk](http://simonmonk.org). 4 | 5 | ![The Maker's Guide to Surviving the Zombie Apocalypse](https://www.nostarch.com/sites/default/files/styles/uc_product/public/zombie_cover-front.png?itok=bVyZ9658) 6 | -------------------------------------------------------------------------------- /Raspberry Pi/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonmonk/zombies/424ea622e71f16947dc00f2fde673dfa2508eeb6/Raspberry Pi/.DS_Store -------------------------------------------------------------------------------- /Raspberry Pi/control_center_bt/control.py: -------------------------------------------------------------------------------- 1 | from Tkinter import * 2 | import serial 3 | import time 4 | 5 | BAUD = 9600 6 | PORT = "/dev/rfcomm0" 7 | 8 | MIN_VOLTS = 11.0 9 | TEMP_MIN = -10.0 10 | TEMP_MAX = 45.0 11 | 12 | class App: 13 | 14 | def __init__(self, master): 15 | 16 | self.frame = Frame(master) 17 | self.frame.pack() 18 | 19 | Label(self.frame, text='Volts').grid(row=0, column=0, sticky=E) 20 | self.volts_var = StringVar() 21 | self.volts_label = Label(self.frame, textvariable=self.volts_var) 22 | self.volts_label.grid(row=0, column=1) 23 | 24 | Label(self.frame, text='Temperature').grid(row=1, column=0, sticky=E) 25 | self.temp_var = StringVar() 26 | self.temp_label = Label(self.frame, textvariable=self.temp_var) 27 | self.temp_label.grid(row=1, column=1) 28 | 29 | Label(self.frame, text='Door').grid(row=2, column=0, sticky=E) 30 | self.door_var = StringVar() 31 | self.door_label = Label(self.frame, textvariable=self.door_var) 32 | self.door_label.grid(row=2, column=1) 33 | 34 | Label(self.frame, text='PIR').grid(row=3, column=0, sticky=E) 35 | self.pir_var = StringVar() 36 | self.pir_label = Label(self.frame, textvariable=self.pir_var) 37 | self.pir_label.grid(row=3, column=1) 38 | 39 | Label(self.frame, text='Fire').grid(row=4, column=0, sticky=E) 40 | self.fire_var = StringVar() 41 | self.fire_label = Label(self.frame, textvariable=self.fire_var) 42 | self.fire_label.grid(row=4, column=1) 43 | 44 | self.ser = serial.Serial(PORT, BAUD, timeout=1) 45 | time.sleep(2) 46 | 47 | 48 | 49 | def read_arduino(self): 50 | self.ser.write('?') 51 | data = volts, temp, door, pir, fire = self.ser.readline().split() 52 | self.volts_var.set(volts) 53 | self.temp_var.set(temp) 54 | self.door_var.set(door) 55 | self.pir_var.set(pir) 56 | self.fire_var.set(fire) 57 | if float(volts) < MIN_VOLTS: 58 | self.volts_label.configure(bg = "red") 59 | else: 60 | self.volts_label.configure(bg = "green") 61 | 62 | if float(temp) < TEMP_MIN or float(temp) > TEMP_MAX: 63 | self.temp_label.configure(bg = "red") 64 | else: 65 | self.temp_label.configure(bg = "green") 66 | 67 | if door == "1": 68 | self.door_label.configure(bg = "red") 69 | else: 70 | self.door_label.configure(bg = "green") 71 | 72 | if pir == "1": 73 | self.pir_label.configure(bg = "red") 74 | else: 75 | self.pir_label.configure(bg = "green") 76 | 77 | if fire == "1": 78 | self.fire_label.configure(bg = "red") 79 | else: 80 | self.fire_label.configure(bg = "green") 81 | 82 | 83 | root = Tk() 84 | root.wm_title('Control') 85 | app = App(root) 86 | 87 | def update(): 88 | app.read_arduino() 89 | root.after(500, update) 90 | 91 | root.after(100, update) 92 | 93 | 94 | root.mainloop() -------------------------------------------------------------------------------- /Raspberry Pi/control_center_usb/control.py: -------------------------------------------------------------------------------- 1 | from Tkinter import * 2 | import serial 3 | import time 4 | 5 | BAUD = 9600 6 | PORT = "/dev/ttyACM0" 7 | 8 | MIN_VOLTS = 11.0 9 | TEMP_MIN = -10.0 10 | TEMP_MAX = 45.0 11 | 12 | class App: 13 | 14 | def __init__(self, master): 15 | self.frame = Frame(master) 16 | self.frame.pack() 17 | 18 | Label(self.frame, text='Volts').grid(row=0, column=0, sticky=E) 19 | self.volts_var = StringVar() 20 | self.volts_label = Label(self.frame, textvariable=self.volts_var) 21 | self.volts_label.grid(row=0, column=1) 22 | 23 | Label(self.frame, text='Temperature').grid(row=1, column=0, sticky=E) 24 | self.temp_var = StringVar() 25 | self.temp_label = Label(self.frame, textvariable=self.temp_var) 26 | self.temp_label.grid(row=1, column=1) 27 | 28 | Label(self.frame, text='Door').grid(row=2, column=0, sticky=E) 29 | self.door_var = StringVar() 30 | self.door_label = Label(self.frame, textvariable=self.door_var) 31 | self.door_label.grid(row=2, column=1) 32 | 33 | Label(self.frame, text='PIR').grid(row=3, column=0, sticky=E) 34 | self.pir_var = StringVar() 35 | self.pir_label = Label(self.frame, textvariable=self.pir_var) 36 | self.pir_label.grid(row=3, column=1) 37 | 38 | Label(self.frame, text='Fire').grid(row=4, column=0, sticky=E) 39 | self.fire_var = StringVar() 40 | self.fire_label = Label(self.frame, textvariable=self.fire_var) 41 | self.fire_label.grid(row=4, column=1) 42 | 43 | self.ser = serial.Serial(PORT, BAUD, timeout=1) 44 | time.sleep(2) 45 | 46 | 47 | 48 | def read_arduino(self): 49 | self.ser.write('?') 50 | volts, temp, door, pir, fire = self.ser.readline().split() 51 | self.volts_var.set(volts) 52 | self.temp_var.set(temp) 53 | self.door_var.set(door) 54 | self.pir_var.set(pir) 55 | self.fire_var.set(fire) 56 | if float(volts) < MIN_VOLTS: 57 | self.volts_label.configure(bg = "red") 58 | else: 59 | self.volts_label.configure(bg = "green") 60 | 61 | if float(temp) < TEMP_MIN or float(temp) > TEMP_MAX: 62 | self.temp_label.configure(bg = "red") 63 | else: 64 | self.temp_label.configure(bg = "green") 65 | 66 | if door == "1": 67 | self.door_label.configure(bg = "red") 68 | else: 69 | self.door_label.configure(bg = "green") 70 | 71 | if pir == "1": 72 | self.pir_label.configure(bg = "red") 73 | else: 74 | self.pir_label.configure(bg = "green") 75 | 76 | if fire == "1": 77 | self.fire_label.configure(bg = "red") 78 | else: 79 | self.fire_label.configure(bg = "green") 80 | 81 | 82 | root = Tk() 83 | root.wm_title('Control') 84 | app = App(root) 85 | 86 | def update(): 87 | app.read_arduino() 88 | root.after(500, update) 89 | 90 | root.after(100, update) 91 | 92 | 93 | root.mainloop() -------------------------------------------------------------------------------- /Raspberry Pi/usb_webcam/monitor.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import time 3 | import pygame 4 | import pygame.camera 5 | import RPi.GPIO as GPIO 6 | 7 | camera_res = (320, 240) 8 | window_size = (640, 480) 9 | red_pin = 18 10 | green_pin = 23 11 | 12 | pygame.init() 13 | pygame.camera.init() 14 | 15 | # initialize GPIO 16 | GPIO.setmode(GPIO.BCM) 17 | GPIO.setup(red_pin, GPIO.OUT) 18 | GPIO.setup(green_pin, GPIO.OUT) 19 | 20 | screen = pygame.display.set_mode(window_size, 0) 21 | 22 | #find, open and start low-res camera 23 | cam_list = pygame.camera.list_cameras() 24 | webcam = pygame.camera.Camera(cam_list[0], camera_res) 25 | webcam.start() 26 | old_image = False 27 | 28 | 29 | def check_for_movement(old_image, new_image): 30 | global c 31 | diff_image = pygame.PixelArray(new_image).compare(pygame.PixelArray(old_image), distance=0.5, weights=(0.299, 0.587, 0.114)) 32 | 33 | ys = range(0, camera_res[1] / 20) 34 | for x in range(0, camera_res[0] / 20): 35 | for y in ys: 36 | if diff_image[x*20, y*20] > 0: 37 | return True 38 | return False 39 | 40 | def led_red(): 41 | GPIO.output(red_pin, True) 42 | GPIO.output(green_pin, False) 43 | 44 | def led_green(): 45 | GPIO.output(red_pin, False) 46 | GPIO.output(green_pin, True) 47 | 48 | count = 0 49 | led_green() 50 | while True: 51 | count = count + 1 52 | new_image = webcam.get_image() 53 | # First time round loop set old_image 54 | if not old_image: 55 | old_image = new_image 56 | scaled_image = pygame.transform.scale(new_image, window_size) 57 | # Pnly check one frame in 10 58 | if (count % 10) == 0 : 59 | if check_for_movement(old_image, new_image): 60 | led_red() 61 | count = 0 62 | old_image = new_image 63 | screen.blit(scaled_image, (0, 0)) 64 | pygame.display.update() 65 | 66 | # check for events 67 | for event in pygame.event.get(): 68 | if event.type == pygame.QUIT: 69 | webcam.stop() 70 | pygame.quit() 71 | sys.exit() 72 | if event.type == pygame.KEYDOWN: 73 | print(event.key) 74 | if event.key == 32: # Space 75 | led_green() 76 | #time.sleep(1.0) -------------------------------------------------------------------------------- /Raspberry Pi/usb_webcam/test.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import pygame 3 | import pygame.camera 4 | 5 | pygame.init() 6 | pygame.camera.init() 7 | 8 | #create fullscreen display 640x480 9 | screen = pygame.display.set_mode((640,480),0) 10 | 11 | #find, open and start low-res camera 12 | cam_list = pygame.camera.list_cameras() 13 | webcam = pygame.camera.Camera(cam_list[0],(320,240)) 14 | webcam.start() 15 | 16 | while True: 17 | #grab image, scale and blit to screen 18 | imagen = webcam.get_image() 19 | imagen = pygame.transform.scale(imagen,(640,480)) 20 | screen.blit(imagen,(0,0)) 21 | 22 | #draw all updates to display 23 | pygame.display.update() 24 | 25 | # check for quit events 26 | for event in pygame.event.get(): 27 | if event.type == pygame.QUIT: 28 | webcam.stop() 29 | pygame.quit() 30 | sys.exit() 31 | -------------------------------------------------------------------------------- /mylist.pickle: -------------------------------------------------------------------------------- 1 | (lp0 2 | S'some text' 3 | p1 4 | aI123 5 | a(lp2 6 | I4 7 | aI5 8 | aI01 9 | aa. --------------------------------------------------------------------------------