make pir digital input 2
make led digital output 13
when start
.forever
..set led to pir
That didn't take long. After a little tweaking on the trim pots on the sensor to adjust its sensitivity, it was firing nicely whenever there was any movement around my desk.
So what next... I'll probably attach one to a battery and a buzzer and put it inside the biscuit jar - we have a seven year old biscuit burglar, but that doesn't actually need code. Then I remembered the new "system" device that lets you run shell commands on the Pi. If I had a camera hooked up...
make pir digital input 17
make system device
make command string
make command string
when start
.forever
..if pir
.forever
..if pir
...set command to "raspistill -o image.jpg"
...tell system to "run"
...tell system to "run"
... wait 10 secs
Of course this overwrites the image each time so:
make i2c device
make clock device
make clockValue string
make system device
make command string
make pir digital input 17
make filename string
when start
.forever
..if pir
...tell clock to "getTime"
...set filename to join clockValue ".jpg"
...set command to "raspistill -o "
...set command to join command filename
...tell system to "run"
...wait 10 secs
make clock device
make clockValue string
make command string
make filename string
.forever
..if pir
...tell clock to "getTime"
...set filename to join clockValue ".jpg"
...set command to "raspistill -o "
...set command to join command filename
...tell system to "run"
...wait 10 secs
Now we use the clock device to get the real time in hours/min/secs (timer just gives us time since the program started - clock actually knows the time of day), and use that to make a filename.
Of course it doesn't have to be a PIR - anything that the Pi can read could be used, and it doesn't have to be a camera command...
No comments:
Post a Comment