0

XRAD'S MOUSY WHEEL
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

XRAD'S MOUSY WHEEL

by XRAD on Mon Feb 11, 2019 5:07 pm

I am tired getting logged out of my work computer. It is behind two locked doors and only I use it. I can't load a move mouse program either. So I built one of these! Nearly truly random 'x' and 'y' motion and an additional independent nearly random time function. I took a few lines of basic servo code and added a bunch of stuff including arduino's random seed using the ATSAMD21 pin 20 (well it could be pin 19...). This is a not pretty looking prototype enclosure. I am using a 12v power supply stepped to 5v 2.5A and a polplu 2808 mini power switch. Of course , the trinket M0 is capable of much more than this simple process, so I added 2 LEDs ;) . One is for the rotating servo and one for the linear servo. They are triggered HIGH when certain servo signal criteria are met.

The cool part about this program is that you can adjust servo travel at same time you are adjusting the 'random' position event. Soooo, if you do not like the linear travel (might be hitting the edge) or rotating travel limits, you can easily adjust them. The rotating servo housing slides vertically on to to end of the toothed rack. But, it is not rigidly fixed to the rack. this allows a bit of vertical play as the wheel rotates, or to make up for my poor housing measurements.

I really wanted to put the whole moving plate under a piece of 1/8th plexi, but the focal zone for my home and work mice is right beyond the sensor hole. More than a few mm's away, and no motion. Anyway, fun build and you can surely use this code for other cool projects /props.....Of course, this mouse box really is made to fit a G500s mouse, but a universal box (to work with most cheap standard sized work mice) could be easily constructed.

I love 'randomness,' so many of my codes incorporate this capability. If you look at my code, you can see that there is :
Code: Select all | TOGGLE FULL SIZE
//some storage for random #'s
long randomNumber;
long randomNumber1;

I ran into some strange servo behavior using the same memory for 'time' and the 'servos' but not for just the servos. Also, I could not use ((x>=y)&&(x<=z)) . Not sure why either. Maybe the loop and random generator are too fast? So I had to settle for on/off LEDs based on < or>. Adds a bit of color to the project. Press the momentary power on button and the wheel centers, and the LEDs light up. Center your pointer on the screen and drop mouse into the Mousy Wheel. 'Never' repeats same pattern !!

Final Code Here:
Code: Select all | TOGGLE FULL SIZE
/***************************************************
     ==========XRAD'S MousyWheel===========
  Tired of that log-off screen?? Can't load that move
  mouse program?  Build one of these! Random seed for
  motion and time delay, makes for a really 'almost
  completly random' event!! Do I smell a two hour lunch?
***************************************************/

#include <Servo.h>

#define LED 3  //PWM  for 'rotating' led
#define LED1 4  //PWM  for 'linear' led

//declare servo object
Servo servo1;//rotate
Servo servo2;//linear

//some storage for random #'s
long randomNumber; //for servos
long randomNumber1; //for time

void setup() {
  pinMode(LED, OUTPUT);
  pinMode(LED1, OUTPUT); 
  digitalWrite(LED, HIGH);
  digitalWrite(LED1, HIGH);
  delay(50);
  servo1.attach (0);//rotate
  servo2.attach (2);//linear
  servo1.write(90);//mid rotator position to set baseline
  servo2.write(60);//mid slider position to set baseline
  randomSeed(analogRead(20));//some pin not used
  delay(5000); //place your mouse down on wheel
}

void loop() {

  //random servo position rotating
  randomNumber = random(30, 150); //random travel (servo min, servo max)
  int pos = randomNumber;
  servo1.write(pos);//move servo1 to new position
  delay(80);
   if (pos <= 90) { //midpoint
    digitalWrite(LED, LOW);
  }
   if (pos >= 91) {
    digitalWrite(LED, HIGH);
  }

  //random servo position linear
  randomNumber = random(10,120); //random travel (servo min, servo max)
  pos = randomNumber;
  servo2.write(pos);//move servo2 to new position
    if (pos <= 65) {  //midpoint
    digitalWrite(LED1, LOW);
  }
   if (pos >= 66) {
    digitalWrite(LED1, HIGH);
  }
 
  //random time delay
  randomNumber1 = random(1000, 5000);//delay in millisecs
  delay(randomNumber1);
}


IMG_3076.JPG
IMG_3076.JPG (210.93 KiB) Viewed 60 times
Last edited by XRAD on Mon Feb 11, 2019 6:33 pm, edited 12 times in total.

XRAD
 
Posts: 229
Joined: Sat Nov 19, 2016 3:28 pm

Re: XRAD'S MOUSY WHEEL

by XRAD on Mon Feb 11, 2019 5:30 pm

some 'paint drying' vids:

https://www.youtube.com/watch?v=JMho3NSqtV8

https://www.youtube.com/watch?v=z8vvJaA ... e=youtu.be

IMG_3061.JPG
IMG_3061.JPG (247.96 KiB) Viewed 60 times


IMG_3062.JPG
IMG_3062.JPG (222.53 KiB) Viewed 60 times


IMG_3065.JPG
IMG_3065.JPG (224.86 KiB) Viewed 60 times

XRAD
 
Posts: 229
Joined: Sat Nov 19, 2016 3:28 pm

Re: XRAD'S MOUSY WHEEL

by XRAD on Tue Feb 12, 2019 10:32 pm

Worked like a champ today!

smiley.jpg
smiley.jpg (6.52 KiB) Viewed 38 times

XRAD
 
Posts: 229
Joined: Sat Nov 19, 2016 3:28 pm

Re: XRAD'S MOUSY WHEEL

by adafruit_support_bill on Wed Feb 13, 2019 6:59 am

Cool project! Thanks for posting.

adafruit_support_bill
 
Posts: 71823
Joined: Sat Feb 07, 2009 10:11 am

Please be positive and constructive with your questions and comments.