I'm a NOOB and have been trying to make a waving sign using an Arduino and a servo. I've searched goggle and couldn't find an answer or maybe I did and didn't realize it.
I want to use a selector switch to control the movement of the servo for continuous movement. I have the code and it works great but I want to add the switch to control different speed and movement.
I'd like P1 to go from 0-80, P2 0-40 and P3 40-80.
I'm hoping the easiest way to do this is to write different code for 3 pins then connect the pins to the switch. Is it possible to write code for 3 pins and how would I do that if it is possible?
Here's the code I'm using now.
#include <VarSpeedServo.h>
VarSpeedServo myservo; // create servo object to control a servo
void setup() {
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop() {
myservo.write(0, 20, true);
delay(10);
myservo.write(80, 20, true);
delay(10);
}
You could wire the switches with a resistor ladder and connect to an analog input. That way you use only one pin. The choice of speed chosen by the analog input reading (if, if else or switch). That would avoid having to read 3 inputs and decode for speed choice. [Here is one site](arduino - What resistors to use to read several buttons with a single analog pin - Electrical Engineering Stack Exchange ors-to-use-to-read-several-buttons-with-a-single-analog-pin) that I found with a Google search for "arduino resistor ladder switches".
Just to note that you would only need to use 1 pole (4 terminals) ... common and 3 switched terminals. Could dedicate 3 inputs on your Arduino or just one as suggested by groundfungus.
groundfungus, that is more than I want to get into but I will if it's the only option.
I'm still looking around and found something that might work but I need to rewrite some code. I'm trying to find the code for 1 Arduino to control 3 different servos all doing different things, then the selector switch should work unless no connection to the other servos will stop it from working.
Looks like you want only one servo operational at any given time.
To connect the switch to 3 inputs, I wouldn't rely on the internal pullup resistor ... I would suggest 2.2K to 4.7K for external pullup resistors, one for each of the 3 inputs. The switch common would be connected to GND.
I want to use only 1 servo but write different code for 3 pins that are all different movement and speed. Then hopefully I can use the switch to select the different pins and that will change the servo movement.