HI, Trying to make three independent momentary NO switches control each color in RGB LED. The script runs but the switches do not control the on/off state of the RGB. The RED diode is turn on without pressing any button. At this point I am lost!
Hi, Want to use independent swithes to control the on/off state of the RGB LED. When the script runs the swithes do not control the RGB. It runs and the RED LED comes on without pressing and switch.
void loop()
{
REDcurrentButton = debounce(REDlastButton); //read debounced state
if (REDlastButton == LOW && REDcurrentButton == HIGH); //if it was pressed…
{
REDlastButton = REDcurrentButton; //toggle the LED value
REDledOn = !REDledOn;
REDlastButton = REDcurrentButton;
digitalWrite(RLED,REDledOn);
// return REDlastButton; //return the current value
}
{
GREENcurrentButton = debounce(GREENlastButton); //read debounced state
if (GREENlastButton == LOW && GREENcurrentButton == HIGH); //if it was pressed…
{
GREENlastButton = GREENcurrentButton; //toggle the LED value
GREENledOn = !GREENledOn;
GREENlastButton = GREENcurrentButton;
digitalWrite(GLED,GREENledOn);
// return GREENlastButton; //return the current value
}
{
BLUEcurrentButton = debounce(BLUElastButton); //read debounced state
if (BLUElastButton == LOW && BLUEcurrentButton == HIGH); //if it was pressed…
{
BLUElastButton = BLUEcurrentButton; //toggle the LED value
BLUEledOn = !BLUEledOn;
BLUElastButton = BLUEcurrentButton;
digitalWrite(BLED,BLUEledOn);
// return BLUElastButton; //return the current value
}}}}
Cross-posting is against the rules of the forum. The reason is that duplicate posts can waste the time of the people trying to help. Someone might spend 15 minutes (or more) writing a detailed answer on this topic, without knowing that someone else already did the same in the other topic.
Repeated cross-posting will result in a suspension from the forum.
In the future, please take some time to pick the forum board that best suits the topic of your question and then only post once to that forum board. This is basic forum etiquette, as explained in the sticky "How to use this forum - please read." post you will find at the top of every forum board. It contains a lot of other useful information. Please read it.
Your inputs are probably not floating, I see what looks like 10k ohm resistors in the photo you posted. On the other hand, you should respond to my post about the declaration, reply #3.
Thought Int = (13,12,8) should have been deleted. Also had a thought maybe my logic is reversed. Using a volt meter, measure 5v at each switch when not press and 0v when press?