Hi all, I've been building a small kinetic sculpture that relies on a flex sensor (glove) to instigate the movement via a servo. Although it works the motion of the servo is too quick. I need the servo to respond instantly to the sensor initially, but reduce its rotation speed, slowing up the sculpture movement thereafter and returning to its original position.
I guess I'm after a sketch that sort of combines the following two sketches I have found online.
I hope I'm making sense..... any help would be much appreciated.
the first sketch
#include <Servo.h>
int flexpin=A0;
int flexpin1=A1;
int pos=90;
int pos1=90;
Servo myservo, myservo1;
int flex[20];
int flex1[20];
int flexsum=0;
int flexsum1=0;
void setup()
{
myservo.attach(7);
myservo1.attach(8);
Serial.begin(9600);
}
void loop()
{
for(int x=0; x<20; x++)
{
flex[x]=analogRead(flexpin);
flex1[x]=analogRead(flexpin1);
flexsum=flexsum+analogRead(flexpin);
flexsum1=flexsum1+analogRead(flexpin1);
delayMicroseconds(14);
}
flexsum=flexsum/20;
flexsum1=flexsum1/20;
if(Serial.available())
{
Serial.println(flexsum);
Serial.println(flexsum1);
delay(100);
}
pos=map(flexsum,870,800,0,90);
pos1=map(flexsum1,870,800,0,90);
myservo.write(pos);
myservo1.write(pos1);
delay(200);
}
the second sketch to reduce speed is
#include <Servo.h>
Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created
int pos = 0; // variable to store the servo position
void setup()
{
myservo.attach(8); // attaches the servo on pin 9 to the servo object
}
void loop()
{
for(pos = 0; pos <= 85; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(70); // waits 15ms for the servo to reach the position
}
for(pos = 85; pos>=0; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(70); // waits 15ms for the servo to reach the position
}
}
Please assist
