Go Down

Topic: Help with project for school (Read 733 times) previous topic - next topic

Hello,

Recently purchased a Inventors Kit for a school project and was hoping to get a servo to respond to a mouse moving up and down the x axis without going beyond the 180 range of the toy servo. I was able to run the servo from the beginners guide and also was able to get it to work based off of a mouses on screen movements. Unfortunately the screen is not going to be visible during use so I need it to not be limited to a area I cant blindly stay in. Any suggestions for other tutorials or project s floating around would be fantastic.

Thank you for your time.

to clarify the second project with the mouse controlled servo was one I found online. My coding skill is not impressive

AWOL

It would be useful to see your work so far, but in its absence:
http://arduino.cc/en/Reference/Constrain
http://arduino.cc/en/Reference/Map
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

// Use the included processing code serial library
import processing.serial.*;       


int gx = 15;
int gy = 35;
int spos=90;

float leftColor = 0.0;
float rightColor = 0.0;
Serial port;                         // The serial port



void setup()
{
  size(720, 720);
  colorMode(RGB, 1.0);
  noStroke();
  rectMode(CENTER);
  frameRate(100);

  println(Serial.list()); // List COM-ports

  //select second com-port from the list
  port = new Serial(this, Serial.list()[1], 19200);
}

void draw()
{
  background(0.0);
  update(mouseX);
  fill(mouseX/4);
  rect(150, 320, gx*2, gx*2);
  fill(180 - (mouseX/4));
  rect(450, 320, gy*2, gy*2);
}

void update(int x)
{
  //Calculate servo postion from mouseX
  spos= x/4;

  //Output the servo position ( from 0 to 180)
  port.write("s"+spos);



  // Just some graphics
  leftColor = -0.002 * x/2 + 0.06;
  rightColor =  0.002 * x/2 + 0.06;

  gx = x/2;
  gy = 100-x/2;

}

This is the code I was using from the online tutorial. From your post's I've gather I should be assigning a set of high and low's somewhere. I can see were the grey note is explaining that section of the code but I don't see how it is controlling it

It works but it sounds like it is pushing the servo beyond its limit

// Use the included processing code serial library
import processing.serial.*;       


int gx = 1;
int gy = 1;
int spos=90;


Serial port;                         // The serial port



void setup()
{
  size(1080, 1080);
 
  frameRate(100);

  println(Serial.list()); // List COM-ports

  //select second com-port from the list
  port = new Serial(this, Serial.list()[1], 19200);
}

void draw()
{
  background(0.0);
  update(mouseY);
 
}

void update(int x)
{
  //Calculate servo postion from mouseX
  spos= x/6;

  //Output the servo position ( from 0 to 180)
  port.write("s"+spos);





  gx = x;
  gy = x;

}



I was able to cut out things I learned I didn't need and switch it to the Y axis as I was hoping to do. I resized it to my screens resolution and changed the division so I am getting 180 degree. I just cant figure out how to add an exception to stop it when it gets to the top of the screen. The servo properly stops at the bottom but I need it to cut out when it reaches the top of the block also, other wise it will burn it out.

Here is the tutorial I am going from

http://arduino.cc/playground/Learning/SingleServoExample

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy