Lines Of Code I Can't Seem To Fix

So this is the line that I need one for each switch?

``````  if ((val == HIGH) && (old_val == LOW)){
state = 1 - state;
delay(10);
}
``````

I don't think so, because then you'll have only one state and only one old_val, so again, only the last will be the significant one.

I know it has to be numbered in away to match the code below. I have tried all sorts of ways but can't come up with the right combination.

``````  val = digitalRead(BUTTON_1);
``````

val = digitalRead(BUTTON_1); val = digitalRead(BUTTON_2); val = digitalRead(BUTTON_3); val = digitalRead(BUTTON_4); The above will wind up with val being whatever digitalRead(BUTTON_4) resulted in, can you see why?

int button1_val; int button2_val; int button3_val; int button4_val;

and then

and testing each of those?

Or creating an array; 4 buttons x (pin #, matching led pin #, on/off state), ie: byte button[4][3]; // because you don't need ints to count less than 256

Then you can loop through checking buttons (with debounce) and if any change, then change the matching led.

The debounce is the part that's going to be interesting. If you want to be able to quickly and smoothly go from button to button then a simple 20+ ms delay "to make sure it's done" won't cut it.

One needs to learn to walk before he learns to run....

If I push the button once in the ideal world the the led turns on. And if I push it again in the ideal world it goes off and I know my code is pure.

But in the real world, pushing the button can easily show up as many button presses. And whenever it shows up as an even number of presses the led might flicker enough to notice but it won't change state. And if I can only take baby steps then I might come to the wrong conclusions about what is happening as lose my lesson in purity.

One should learn about arrays as a way of organizing data to make using it easier, right from the start. Program = Code + Data. If your data is tossed down so that each piece has to be picked up separately to use then your code won't be much better if not worse. So at least group things together that are to be processed together and don't forget that for-next or while loops, or even the Arduino loop() can take you from one element to the next just using a simple index. And if it's a two dimensional array (hello, spreadsheet?) then a loop inside a loop will let you get them all.

I hope there's examples of that on the Arduino site but if there aren't then we do need a primary school section somewhere on the board or forum. Arrays and loops are real beginners subjects in every computer language manual I have seen, and I've seen plenty.