Hello I am John
and I'm very new to this I sort of understand the code I know I can just down load it however can someone show me how to hook everything up and tge hardware you used
I am trying to control multiple servos with double pole double throw switches for each and use the other side of the switch for signaling lights
Ignore the pot example. The sweep example shows you how to go 0 o 180 the back from 180 to 0. That is what you want to do. Now you need to connect the toggle switch and read it via a digitalRead()
Here is how to connect the toggle
This sketch (program) show how to turn an LED OFF/ON with the toggle switch
You need to figure out how to combine the relavent parts of both sketches to do what you want.
/*
State change detection
This example shows how to detect when a toggle switch changes from off to on
and on to off with an LED indicator
The circuit:
- Toggle switch connected between pin 2 and GND
- 5.1K resistor connected between pin 2 and 5V
*/
const int buttonPin = 2; // the pin that the switch is attached to
byte buttonState = 0; // current state of the button
byte lastButtonState = 0; // previous state of the button
void setup()
{
// initialize the button pin as a input:
pinMode(buttonPin, INPUT_PULLUP);
// initialize the LED as an output:
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);
// initialize serial communication:
Serial.begin(9600);
}
void loop()
{
// read the pushbutton input pin:
buttonState = digitalRead(buttonPin);
// compare the buttonState to its previous state
if (buttonState != lastButtonState) // if the state has changed
{
if (buttonState == LOW)
{
// if the current state is LOW then the button went from off to on:
Serial.println("on");
digitalWrite(LED_BUILTIN, HIGH);
}
else
{
// if the current state is HIGH then the button went from on to off:
Serial.println("off");
digitalWrite(LED_BUILTIN, LOW);
}
// Delay a little bit to avoid bouncing
delay(50);
}
// save the current state as the last state, for next time through the loop
lastButtonState = buttonState;
}
Jim, we need to keep things as simple as possible for @johnd1024 at this stage of learning. There is (probably) no need for the 5.1K resistor. There is (probably) no need for the wire from the resistor to 5V. There is no need for the plugblock. I'm certain you know these things as well as, if not better than, I do. Can you not find a more suitable diagram with fewer extraneous components and connections?
I do appreciate that you did not present that often used diagram showing all the different ways of connecting buttons. That must scare the sh*t out most beginners!
For the toggle switch, I would recommend using the center common pin to connect to the Arduino digital pin and the other two switch terminals to the voltage references ( one to ground, one to 5V). This way the switch will output either a high or low depending on position and only 1 digital pin is needed for the toggle switch.
thank you all for such good advice i will be doing each of this projects in the coming week or 2
i have been swamped at work however i see a break coming and i can get this project under way
will keep you all up to date on my progress
again thanks for your time