Playing Laser Cat
I don't know why but we have two cats. At some points in our family life we have had three cats. I'm sure that there is medication available for this feline collection disease, but in the meantime we can easily distract them from destroying our furniture by using a small laser light playing around the room. They enthusiastically follow it - again, not sure why.
The problem is that I'm lasier (pun intended) than them, so I don't want to be wasting valuable datasheet reading time pretending to be interested in their pursuits. Recently I did some investigating around matching a servo to an ATTiny85 which got me thinking about maybe using two servos in a "pan and tilt" arrangement for this project. The resulting contraption (Cat Laser Toy?) might randomly move the laser around until the cats die are happy.
I researched pan and tilt camera mounts on Thingiverse and settled on the following design.
As I wanted to add some electronics to the project, and also thought a larger base might be more stable, I started by redesigning the base to attach a box underneath. In the end I did separate the box and the top because I could print the box "upside-down" and halve the printing time (and filament usage).
I added a hole on the side for power (which I had to expand in the end to fit the cable) and I also added a hole for laser/servo wires at the top. You can see some of these FreeCad techniques on an earlier blog.
/* Attiny85 based servo code to drive the cats mad with random laser movement. OneCircuit www.onecircuit.blogspot.com Sunday 11 April 13:31:51 AEST 2021 Servo_ATTinyCore.h is part of the ATTinyCore family found at https://github.com/SpenceKonde/ATTinyCore */ #include <Servo_ATTinyCore.h> Servo myservo; // create servo object int updownservo = PB0; // pin for vertical servo int side2sideservo = PB1; // pin for horizontal servo // limits of movement for horizontal servo int sidelower = 125; int sidemiddle = 90; int sideupper = 55; // limits of movement for vertical servo int updownlower = 135; int updownmiddle = 125; int updownupper = 115; // slow these down for an older cat? int timedelay = 400; int movementdelay = 400; // generic servo moving - with detaching at the end // which eliminates jitter void movetheservo(int movepos, int whichservo) { myservo.attach(whichservo); myservo.write(movepos); delay(movementdelay); myservo.detach(); } void setup() { // a bit of overhead for a "random" number pinMode(A3, INPUT); int readanalog = analogRead(A3); randomSeed(readanalog); // initialise to centre of area movetheservo(updownmiddle, updownservo); movetheservo(sidemiddle, side2sideservo); delay(timedelay); } void loop() { // go find some random position int movevertical = random(updownupper, updownlower); int movehorizontal = random(sideupper, sidelower); // go find a random time to hold position timedelay = random(100, 200); // move the servos movetheservo(movevertical, updownservo); delay(timedelay); movetheservo(movehorizontal, side2sideservo); delay(timedelay); }
The project works well and at least one cat is happier some of the time - so, result?
No comments:
Post a Comment