
PinMode(GROUND_JOY_PIN, OUTPUT) //pin A2 shall be used as outputĭigitalWrite(VOUT_JOY_PIN, HIGH) //set pin A3 to high (+5V)ĭigitalWrite(GROUND_JOY_PIN,LOW) //set pin A3 to low (ground) PinMode(VOUT_JOY_PIN, OUTPUT) //pin A3 shall be used as output #define BUTTON_PIN 2 //number of the pushbutton pin #define XJOY_PIN A1 //X axis reading from joystick will go into analog pin A1 #define VOUT_JOY_PIN A2 //joystick +5 V pin will connect to Arduino analog pin A2 #define GROUND_JOY_PIN A3 //joystick ground pin will connect to Arduino analog pin A3
Potentiometer servo motor arduino code#
The code would be similar to this #include If you use the code from the link I shared you would need to add the button pin, read the button state, and save the potentiometer value when the button is pressed. You could add a button to make the process easier. Myservo3.write(pos) // tell servo to go to position in variable 'pos'įor(pos = 0 pos <= 180 pos +=1) // goes from 0 degrees to 180 degreesĭelay(15) // waits 15ms for the servo to reach the position Myservo2.write(pos) // tell servo to go to position in variable 'pos'ĭelay(10) // waits 15ms for the servo to reach the position Myservo1.write(pos) // tell servo to go to position in variable 'pos'ĭelay(5) // waits 15ms for the servo to reach the position

Myservo3.attach(5) // attaches the servo on pin 9 to the servo objectĭelay(2000) ////stops motor for 8 secondsįor(pos = 180 pos>=0 pos-=1)// goes from 180 degrees to 0 degrees Int pos =0 // variable to store the servo position twelve servo objects can be created on most boards Servo myservo3 // create servo object to control a servo Is there a way to control the servos with an external joystick and the movements be live recorded into arduino code so I can run the code back in Arduino? I am wanting the Servo’s to move to the mp3 accurately so they look like they are talking. I have the following code so when I press a button the Servos move to a random Servo code I found. I am wanting to Press a Button and both audio and Servos begin a sequence.

I am creating 3 fish that sing with 6 motors (3 x mouths and 3x eyes)
