1
0
mirror of https://github.com/Adam-Ant/WatchedPotNeverBoils synced 2024-06-14 11:07:23 +00:00

Initial Commit

This commit is contained in:
Adam Dodman 2017-10-02 22:30:36 +01:00
commit f71adf4155
3 changed files with 90 additions and 0 deletions

7
Readme.md Normal file
View File

@ -0,0 +1,7 @@
# A Watched Pot Never Boils
This repo uses a Raspberry Pi and a 433Mhz remote controlled socket to enforce the old idiom, "A Watched Pot Never Boils".
This code is unmaintained, and was written at 4am after seeing a video by Tom Scott that contained this very concept.
A writeup of how this was done can be found on my blog, [here]()

44
WatchPotNeverBoils.ino Normal file
View File

@ -0,0 +1,44 @@
/*
Send an n to turn on, a f to turn off
*/
#include <RCSwitch.h>
RCSwitch mySwitch = RCSwitch();
int inbyte = 0; // for incoming serial data
void setup() {
Serial.begin(9600);
// Transmitter is connected to Arduino Pin #10
mySwitch.enableTransmit(10);
// Optional set protocol (default is 1, will work for most outlets)
// mySwitch.setProtocol(2);
// Optional set pulse length.
mySwitch.setPulseLength(242);
// Optional set number of transmission repetitions.
// mySwitch.setRepeatTransmit(15);
}
void loop() {
/* Same switch as above, but using binary code */
if (Serial.available() > 0) {
inbyte = Serial.read();
switch (inbyte) {
case 102:
mySwitch.send("000011110000000000000000");
case 110:
mySwitch.send("000011110000000011000000");
}
}
}

39
cv.py Normal file
View File

@ -0,0 +1,39 @@
import io
import picamera
import cv2
import numpy
import serial
#Load a cascade file for detecting faces
face_cascade = cv2.CascadeClassifier('/home/pi/opencv-3.3.0/data/haarcascades/haarcascade_frontalface_default.xml')
ser = serial.Serial('/dev/ttyACM0')
while True:
#Create a memory stream so photos doesn't need to be saved in a file
stream = io.BytesIO()
#Get the picture (low resolution, so it should be quite fast)
#Here you can also specify other parameters (e.g.:rotate the image)
with picamera.PiCamera() as camera:
camera.resolution = (320, 240)
camera.capture(stream, format='jpeg')
#Convert the picture into a numpy array
buff = numpy.fromstring(stream.getvalue(), dtype=numpy.uint8)
#Now creates an OpenCV image
image = cv2.imdecode(buff, 1)
#Convert to grayscale
gray = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
#Look for faces in the image using the loaded cascade file
faces = face_cascade.detectMultiScale(gray, 1.1, 5)
print("Found "+str(len(faces))+" face(s)")
if len(faces) > 0:
ser.write(b'f')
else:
ser.write(b'n')