Hello everyone, I'm new to the Arduino community and have only been learning for a couple of days. I have greatly enjoyed learning and have discovered a lot from looking at these forums. However I'm stumped on my latest endeavor.

I've managed to get each button to control a separate LED through a single analog wire. The problem is I can not figure out for the life of me how to not continue to repeat the effect. For instance, when I press button one, led one increases in brightness. If I hold down button one, led one continues to cycle through it's brightness level.

In short I just want a held button to act as a single button action and not continually repeat. One press, one action, until it is released and pressed again. I've tried several ways of doing this to no avail so I'll share my raw setup up and code. If you can help that would be great, and feel free to be honest if I've just done something completely backwards. I may be a noob but I can take some criticism. Thanks in advance.

And of course, if you want to use this code and/or setup feel free, just please share your uses/discoveries.

LED ONE, when button is pressed increase one level in brightness untill button is released, and pressed again, then increase in brightness againLED TWO, only light whil button two is pressed and held.LED THREE and FOUR, Light when button is pressed. Turn off when button is pressed for a second time

if(switcharrayval > 230 && switcharrayval < 300) // Check if switch three is pressed { delay(10); switchthree=!switchthree; // If so reverse the value of switch three digitalWrite(ledthreePin, switchthree); // Set ledthree ledthree to same value as switch three }

if(switcharrayval > 150 && switcharrayval < 225) // Check if switch four is pressed { switchfour=!switchfour; // If so reverse the value of switch four digitalWrite(ledfourPin, switchfour); // Set ledfour to same value as switch four }

The code is a bit confusing. I would write it so that the first thing you do is to set a variable that indicates what switch is being pressed.Then write the code that does the action you want.You will need a variable that notes the time when the button was first pressed using millis(), so you will need another that notes what switch was pressed the last time through the loop. I can't see any of that in your code and you need that sort of information if you want to do what you say.

I know the code I provided won't give the desired result, it was just more or less the foundation that I'm building off of.

I've been fighting with this all night and finally stripped it down to a single led, coded it as if it was a digital switch just provding high or low, and not an analog. Then I just went back and added my if() statements. Finally it works! Now I'd just need to add separate booleans for each of my four LEDS but I might actually be able to handle that.

I manged to get all four switches controlling their own LED, push on, push off, held buttons ignored. So I'm excited about that. However I still have the obvious issue of the switches bouncing. I've debounced single switches using delay() but I've been told this is bad practice. On top of that I don't really see that being feasible with this switch array. Also with it all being through one analog pin I don't see a hardware solution. I know to you guys this is probably a simple problem but I feel that if I don't really learn and understand these basics I'm just shooting myself in the foot before I learn to walk.

Here is my current code, any comments are always welcome, and of course examples. Thanks so much!

// Define Constantsconst int switcharrayPin=A0; // Set switch array pin to analog pin 0const int ledonePin=11; // Set LED pin to 11const int ledtwoPin=10; // Set LED two pin to 10const int ledthreePin=9;// Set LED three to pin 9const int ledfourPin=6; // Set LED four to pin 6

void setup(){ pinMode (switcharrayPin, INPUT); //set switch array pin to an input pinMode (ledonePin, OUTPUT); // set LED one pin to output pinMode (ledtwoPin, OUTPUT); // set LED two pin to output pinMode (ledthreePin, OUTPUT); //set LED three pin to output pinMode (ledfourPin, OUTPUT); //set LED four pin to output}

void loop(){

// LED ONE CHECK AND SWITCH CODE switcharrayvalue=analogRead(switcharrayPin); // Read Switch Array if(switcharrayvalue > 350 && switcharrayvalue < 550 && switchonelast==false)// See if switch one is pressed when it was not pressed before { switchonecurrent = !switchonecurrent; // If so, flip switch ones value switchonelast=true; // If so, make switch ones last state to true } else { if(switcharrayvalue < 350 || switcharrayvalue > 550)// See if button one is not pressed { switchonelast=false; // If it's not, set switch ones last state to false } } digitalWrite(ledonePin,switchonecurrent); // Write switch ones current state to LED One

// LED TWO CHECK AND SWITCH CODE switcharrayvalue=analogRead(switcharrayPin); // Read Switch Array if(switcharrayvalue > 320 && switcharrayvalue < 350 && switchtwolast==false)// See if switch two is pressed when it was not pressed before { switchtwocurrent = !switchtwocurrent; // If so, flip switch twos value switchtwolast=true; // If so, make switch twos last state to true } else { if(switcharrayvalue < 320 || switcharrayvalue > 350)// See if button two is not pressed { switchtwolast=false; // If it's not, set switch twos last state to false } }

digitalWrite(ledtwoPin,switchtwocurrent); // Write switch twos current state to LED two

// LED THREE SWITCH AND CODE switcharrayvalue=analogRead(switcharrayPin); // Read Switch Array if(switcharrayvalue > 240 && switcharrayvalue < 260 && switchthreelast==false)// See if switch three is pressed when it was not pressed before { switchthreecurrent = !switchthreecurrent; // If so, flip switch threes value switchthreelast=true; // If so, make switch threes last state to true } else { if(switcharrayvalue < 240 || switcharrayvalue > 260)// See if button three is not pressed { switchthreelast=false; // If it's not, set switch threes last state to false } }

digitalWrite(ledthreePin,switchthreecurrent); // Write switch threes current state to LED three

// LED FOUR CHECK AND SWITCH CODE switcharrayvalue=analogRead(switcharrayPin); // Read Switch Array if(switcharrayvalue > 190 && switcharrayvalue < 220 && switchfourlast==false)// See if switch four is pressed when it was not pressed before { switchfourcurrent = !switchfourcurrent; // If so, flip switch fours value switchfourlast=true; // If so, make switch fours last state to true } else { if(switcharrayvalue < 190 || switcharrayvalue > 220)// See if button four is not pressed { switchfourlast=false; // If it's not, set switch fours last state to false } }

digitalWrite(ledfourPin,switchfourcurrent); // Write switch fours current state to LED four

}

Any fool can criticize, condemn and complain - and most fools do. ~ Benjamin Franklin

Look at the blink without delay example, that is the basis of what you want to do.You get the time now with millis and compair the time now whit the time you want certain actions to finish or change.Also look up the concept of a state machine it is what you want to implement.