cant your sharp track your hand at any farther distance? just curious. Also, please post the code, it looks different from your forum post. Very well done, no jerky movements, it is slick
Yes the sharp can track my hand at the farther distance than shown in the video.
Code:
#include <Servo.h> int sharp1 = 0; // right sensor analogue pin int sharp2 = 1; // left sensor analogue pin int leftdist = 0; // variable to store left sensor reading int rightdist = 0; // variable to store right sensor reading int headpin = 8; // pin to which servo is connected int pos = 90; // center position for servo
Servo head; // create a servo object
void setup() { head.attach(headpin); head.write(pos); //center the servo }
There is actually no need for the faceforward() function, as you’re already performing head.write(pos); at the end of every loop. Also, since you have only ‘if’ comparisons and no ‘else if’ or ‘else’ comparisons, when leftdist and rightdist are both < 400, you actually end up calling faceforward() then faceright() then faceleft() and then writing with head.write(pos) after that, all in the same iteration of loop().
and yeah i had figured it out earlier that there was no need to put faceforward() function but i was too lazy to change the code and test it again because of my arduino IDE.(see the forum post here maybe you can give a solution)
Nice suggestion! I would love to see video on how this changes the response. I still haven’t recieved my sharps yet… :( I’ll be playing with this soon enough.