Using a SPDT Switch to change programs

I am trying to use a switch to change between to different loops of code - initially, to prove the concept, I'm just trying to make one LED blink if the switch is in position 1, and another LED blink if the switch is in position 2. However, I have no idea how to do this. I've got the middle lug of the switch connected to a digital pin on the arduino, and the other lug of the switch going to ground. I think I need to set the switching pin as an input and enable pullup, but beyond this I have know idea how to write the code for this. All the solutions I've found on the web haven't worked at all. Can anyone help?

Post your best coding attempts (with code tags).
This might help.
Leo..

if(digitalRead(switchPin) == HIGH) { // if switchpin is HIGH
  // first LED code here
}
else { // if LOW
  //second LED code here
}

Welcome to the forum.

Suggest you do some reading about Arduino and switches.

Here is a great place to start.

Nick Gammon Switches

FYI

Wawa:
Post your best coding attempts (with code tags).
This might help.
Leo..

if(digitalRead(switchPin) == HIGH) { // if switchpin is HIGH

// first LED code here
}
else { // if LOW
  //second LED code here
}

Well I posted your code in, and it worked perfectly. I had previously tried very similar coding with no success. No idea what has changed, but all is working as I want it to so I won't complain... thanks!

I was answering on the same lines as Wawa, but you talk of the double throw switch's ground and "the" (as opposed to "one of the") other lug, so sounds like it's a single throw switch not a double throw? (Single throw is all you need....)

kman42:
I had previously tried very similar coding with no success.

Lemme guess...
Common mistake learning opportunity is using = instead of ==.

You can also use

if(digitalRead(switchPin)) { // if switchpin is HIGH

Leo..

Simple Guide to Switches