Hey guys - im using a modified 'knob' sketch to control 4 sail winch servos independently, while attached to amplifier tone controls, Its all working perfectly - thanks to the help of some of the community members !
I need to be able to store and recall the settings when the device is in use, but there is no need to permanently store a setting, i just want to be able to do it while the device is turned on.
So i have two push buttons, one for 'save' and one for 'recall' . i have NO IDEA how to do this, my tutor seemed to think that i could;
1.create 4 new variables
2.press button A to copy the analog values which are received by the arduino via potentiometer input (one for each corresponding servo)
- Press the other button (B) to get the values back.
My questions are:
So would the buttons be plugged into digital or analogue input?
What code functions are used for temporarily storing 4 analogue values (each between 0-1023) ?
How would i recall these values and send them to the servos, ordering them to move to the saved position?
my current code is below.
PLEASE don't refrain from commenting as any advice is taken on board!
thanks, Si
#include <Servo.h>
Servo myservo1; // create servo object to control a servo
Servo myservo2;
Servo myservo3;
Servo myservo4;
int potpin = 0; // analog pin used to connect the potentiometer
int val1; // variable to read the value from the analog pin
int potpin2 = 1; // analog pin used to connect the potentiometer
int val2; // variable to read the value from the analog pin
int potpin3 = 2; // analog pin used to connect the potentiometer
int val3; // variable to read the value from the analog pin
int potpin4 = 3; // analog pin used to connect the potentiometer
int val4; // variable to read the value from the analog pin
void setup()
{
myservo1.attach(9); // attaches the servo on pin 9 to the servo object
myservo2.attach(10); // attaches the servo on pin 10 to the servo object
myservo3.attach(5); // attaches the servo on pin 11 to the servo object
myservo4.attach(6); // attaches the servo on pin 12 to the servo object
}
void loop()
{
val1 = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
val1 = map(val1, 0, 1023, 1500, 2425); // scale it to use it with the servo (value between 0 and 180)
myservo1.writeMicroseconds(val1); // sets the servo position according to the scaled value
// waits for the servo to get there
val2 = analogRead(potpin2); // reads the value of the potentiometer (value between 0 and 1023)
val2 = map(val2, 0, 1023, 1500, 2425); // scale it to use it with the servo (value between 0 and 180)
myservo2.writeMicroseconds(val2); // sets the servo position according to the scaled value
val3 = analogRead(potpin3); // reads the value of the potentiometer (value between 0 and 1023)
val3 = map(val3, 0, 1023, 1500, 2425); // scale it to use it with the servo (value between 0 and 180)
myservo3.writeMicroseconds(val3); // sets the servo position according to the scaled value
val4 = analogRead(potpin4); // reads the value of the potentiometer (value between 0 and 1023)
val4 = map(val4, 0, 1023, 1500, 2425); // scale it to use it with the servo (value between 0 and 180)
myservo4.writeMicroseconds(val4); // sets the servo position according to the scaled value
delay(15);
}