tag:blogger.com,1999:blog-4933295803079622480.post7544261747387175269..comments2023-10-30T02:04:40.610-07:00Comments on Dan Thompson: Arduino Push Button ON/OFF ExampleDan Thompsonhttp://www.blogger.com/profile/09932336949749833460noreply@blogger.comBlogger6125tag:blogger.com,1999:blog-4933295803079622480.post-21772183692194464352016-09-04T23:12:17.224-07:002016-09-04T23:12:17.224-07:00You can control it via Visual Basic form from your...You can control it via Visual Basic form from your computer<br /><br /><a href="http://www.computeraidedautomation.com/Arduino-and-Visual-Basic-ON-OFF-buttons" rel="nofollow">http://www.computeraidedautomation.com/Arduino-and-Visual-Basic-ON-OFF-buttons</a>Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-4933295803079622480.post-71413727143703929552016-07-08T14:15:56.452-07:002016-07-08T14:15:56.452-07:00Hi Dan,
I know this is a bit old but all the same...Hi Dan, <br />I know this is a bit old but all the same... very well explained. Thanks for taking the time and effort! :)<br /><br />I have been playing around with it to handle 2 or more Buttons/LEDs, it is not working yet but I still have high hopes.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-4933295803079622480.post-57879486789814013682014-02-25T16:54:20.043-08:002014-02-25T16:54:20.043-08:00I attempted modifying this to control a relay rath...I attempted modifying this to control a relay rather than a LED, by changing a few values, but copied and pasted parts to duplicate the system but with additional parts. I have a 4ch relay shield, and 4 push buttons, in the example ill provide below youll notice what ive done. can you point me in the right direction here??<br /><br /><br /><br />const int buttonPin = 2; // the number of the pushbutton pin<br />const int buttonPin1 = 3; //Additional button for Relay #1<br />const int ledPin = 7; // the number of the LED pin<br />const int ledPin1 = 6; // Pin assigned to second relay addition<br /><br />// Variables will change:<br />int ledState = LOW; // the current state of the output pn WAS set to HIGH for default<br />int ledState1 = LOW;<br />int buttonState; // the current reading from the input pin<br />int buttonState1;<br />int lastButtonState = LOW; // the previous reading from the input pin<br />int lastButtonState1 = LOW; // Addition, plus all lines without comments<br /><br /><br />long lastDebounceTime = 0; <br />long lastDebounceTime1 = 0; <br />long debounceDelay = 50; <br /><br />void setup() {<br /> pinMode(buttonPin, INPUT);<br /> pinMode(buttonPin1, INPUT);<br /> pinMode(ledPin, OUTPUT);<br /> pinMode(ledPin1, OUTPUT);<br /> Serial.begin(9600);<br />}<br /><br />void loop() {<br /> int reading = digitalRead(buttonPin);<br /> int reading1 = digitalRead(buttonPin1);<br /> <br /><br /> // If the switch changed, due to noise or pressing:<br /> if (reading != lastButtonState) {<br /> // reset the debouncing timer<br /> lastDebounceTime = millis();<br /> if (buttonState == HIGH) {<br /> ledState = !ledState;<br /> Serial.println(ledState);<br /> } <br /> } <br /> <br /> if ((millis() - lastDebounceTime) > debounceDelay) {<br /> buttonState = reading;<br /> }<br /> digitalWrite(ledPin1, ledState1);<br /> lastButtonState1 = reading; <br /> if (reading != lastButtonState) {<br /> // reset the debouncing timer<br /> lastDebounceTime1 = millis();<br /> <br /> if (buttonState == HIGH) {<br /> ledState1 = !ledState1;<br /> Serial.println(ledState1);<br /> } <br /> } <br /> <br /> if ((millis() - lastDebounceTime) > debounceDelay) {<br /> buttonState1 = reading;<br /> }<br /> digitalWrite(ledPin1, ledState1);<br /> lastButtonState = reading1;<br />}<br />Justin Mullishttps://www.blogger.com/profile/08473653903214535278noreply@blogger.comtag:blogger.com,1999:blog-4933295803079622480.post-80033636851317602142013-09-16T19:33:28.049-07:002013-09-16T19:33:28.049-07:00Works great for me!
Matt DWorks great for me! <br /><br />Matt DAnonymoushttps://www.blogger.com/profile/13759213391988007155noreply@blogger.comtag:blogger.com,1999:blog-4933295803079622480.post-54092442736339922492012-12-28T21:59:45.596-08:002012-12-28T21:59:45.596-08:00Seems like there is a problem with
if (buttonSta...Seems like there is a problem with <br /><br />if (buttonState == HIGH) {<br /><br />being that buttonState never changes.. Instead this should be<br /><br />if (reading == HIGH) {<br /><br />Besides that it works great! Thanks<br />Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-4933295803079622480.post-1855366068107287032012-01-19T21:33:55.965-08:002012-01-19T21:33:55.965-08:00Very clear instruction. Electronic students can be...Very clear instruction. Electronic students can be helped through.<br /><br /><a href="http://www.jayconsystems.com" rel="nofollow"> what is arduino </a>F.Thttps://www.blogger.com/profile/05677682417879630206noreply@blogger.com