Hello,
I am new to Arduino, and am having some trouble with the coding in C. I am making an led lamp fluctuate in brightness from 0-255 and back from 255-0. I have to Hold my button in in order to make the fluctuations happen instead of just a simple button press, and after I am finished, I can not terminate the loop buy hitting the button again. Please help. Code:
int switchPin = 7;
int ledPin = 9;
int ledIntensity = 0;
int ledFade = 5;
int lastButton = 0;
int currentButton = 0;
boolean Pause = true;
You are not reading the switch state with the delay()s in your code. Get rid of them. There must be something like 514582548528 bazillion posts on how too not use delay. Mr. Google will help.
Thank you so much,
I have had Arduino for a week, and C syntax is a little different that what I am used to. I appreciate all of the input. I can not let a problem go, so it has been driving me crazy. I will run this without the delays to see if the switch response is much better.
Thank you so much again, I am still unclear on how to take signal back off of the button to stop the loop and kill the led all together, and also i shouldn't have to hold the button in to supply signal. I am wanting to press the button once, have the led cycle as stated in syntax and then terminate signal and loop on
another button press.
I am having to hold the button in to cycle, once i press it sets the initial signal to power on led but holds until i keep button held, then when i release the button it holds again. and I have to reset the unit in order to stop the high signal to the led in order to restart the program.
I think I am missing something simple, but I have been looking at it so long and have tried so many different codes that I am lost in it now, lol. Almost blurred out to what I am trying to do
Save the millis() value at the time that the start action happens (writing a value to the LED). Then, each time through loop(), check whether the required wait period has elapsed by subtracting the start time from the millis() value now. If the period has elapsed then act accordingly (change the intensity variable and write to the LED) and save the start time for the next activity. If not, then go round loop() again, taking other actions and/or reading inputs. What do you want to do if the button is found to be pressed ?
That makes perfect sense, thank you for dumbing it down for me. I want the button press to start fluctuations and to stop the fluctuations taking power from the led and setting value back == 0
I suggest that you declare a boolean value, set it initially to false and only do the variation in intensity when it is true.
When the button becomes pressed (NOTE : not is pressed) and the boolean is false set it to true to start the sequence. When the button becomes pressed and the boolean is true set it to false and set the intensity variable to zero and write it to the LED.
}
return 0;
}
}
I'm not sure if I am any closer, at work at the moment. I would like to sit in front of my computer at home to actually test this. Again, I will change the delays, and sort some things around later this evening. Thank you for going through the trouble.
These are all the places that buttonState appears in your code. Since buttonState is always false, and 7 is always true, the first if statement will always evaluate to true and the second will always evaluate to false.