I have a number of Arduino books and have done lots of reading and have tried to write a few sketches but the more I do the more confused I get. I have a rotary switch with 4 positions that I am going use to control the inputs into my Arduino Uno Rev3. I want to monitor the 4 inputs and trigger 4 output pins for each input. I am using some Sparkfun power driver shields to drive some multi LED lamps. I want these to light for 2 seconds and go off for 2 seconds and repeat, changing which lamps light according to what input they receive. Best I can tell is that I want to use "blink without delay" and possibly "switch case". I am looking for some guidance on how to structure my sketch. Below is an example of what I am trying to do:

@ Nick, sorry about the semicolon slip. It was late and I was tired. As for LEFT that is what I am assigning that output instead of say LED. My other outputs would be RIGHT, DOUBLE, and CAUTION and use a combination of pins as their outputs. My other inputs would be labeled SWITCHR, SWITCHD, and SWITCHC.

@michinyon I want the FETs on my two power driver boards to trigger at the same time. That gives me 4 input pins and 6 output pins with several free pins on my UNO.

I .... have tried to write a few sketches but the more I do the more confused I get.

Ok I think maybe it's worth a bit of a back up KSf.

What sketches have you tried, and (more to the point) what happened that shouldn't have or didn't happen that should have? Have you resolved those problems? Did you get the blink and switch case sketches under you belt successfully?

And lastly, what specifically has confused you?- perhaps someone here can help clarify a stumbling block which is holding you up?

Here is where I am at. I decided to make a sketch for one section of my code. The "LEFT" part using the "Blinking LED" sketch. I figured if I can make this work then the rest should be fairly straightforward. When I read that "delay" pauses everything, I realized that this won't work because I need to monitor my inputs for changes and decided to try the Blink Without Delay sketch and change things to my designations. Here is what I came up with:

Quote

constint LEFT = 5; // the number of the LED pinconstint LEFT = 6;constint LEFT = 9;constint LEFT = 10;constint SWITCH = 4;

int ledState = LOW; // ledState used to set the LEDlong previousMillis = 0; // will store last time LED was updated

long interval = 2000; // interval at which to blink (milliseconds)

voidsetup() {// set the digital pin as output:pinMode(LEFT, OUTPUT); }

voidloop(){unsignedlong currentMillis = millis();

if(currentMillis - previousMillis > interval) {// save the last time you blinked the LED previousMillis = currentMillis;

// if the LED is off turn it on and vice-versa:if (ledState == LOW) ledState = HIGH;else ledState = LOW;

// set the LED with the ledState of the variable:digitalWrite(LEFT, ledState); }}

When I "verify" it shows problems with using LEFT multiple times. From what I have read I understand that I want the Uno, whenever it see's LEFT, to know that this is an output and know that the output will be pins 5,6,9,10. I am assuming that because "verify" shows that this is a problem, that I can't use LEFT to define all 4 output pins. If that is so, how do I need to change this so that when I have an input on pin 4, I output to pins 5,6,9,10?

OK. Based on the questions you guys were asking me about "LEFT", I modified it and now "verify" is happy with the result. I will post the new version below. Can someone confirm for me if this will infact output to pins 5,6,9,10 when it receives an input on pin 4 and that the outputs will blink on and off @ 2 second intervals?

I made the suggested changes and loaded the sketch and used some LEDs on my breadboard and have some success. The LEDs do blink in 2 second intervals but they blink without input on pin 4. How should I remedy this? I believe I am getting close. Once this piece of code it working properly I can repeat it for the other 3 sections and then I will just have to possibly use switchcase? to allow me to monitor the 4 inputs for change of state. Here is the revised code, what am I missing?

Well, you aren't doing anything with that read. As taz pointed out, you need to have an if to check if that switch is set, and if it is, perform your block of led code. As it stands, the led code runs all the time regardless of the switch

If you haven't already done so, I'd recommend working through the digital read serial tutorial to see how to wire a switch and read its state. On the subject of wiring, you haven't shown us how it's wired....

additional link supplied by jim, i request you to go through a basic tutorial, which i myself start with when i first had my arduino, read it, its so fun and make things so clear and comprehensive, and im pretty sure you will like it.

Look at some of the examples that come with the IDE. This reads the switch but ignores the result. As taz3m suggests, you need to save the result in a variable and compare to LOW or HIGH (not low or high).

Please post technical questions on the forum, not by personal message. Thanks!