I wrote a shorter and clear way by watching this video, thanks a lot btw: if(btnState && !btnStatePrev) ledState = !ledState; digitalWrite(led, ledState); btnStatePrev = btnState;
Toggling a pin can be reduced to one line of code: digitalWrite(pin, !digitalRead(pin)); And there's no need to keep track of the previous state because an internal register in the processor is already doing that.
but then it doesnt toggle it if your using a button because if you dont instantly press the button its going to start running it over and over so nothing really happens
Thanks you helped me crack the code! I learned that there is one cycle of the loop where the buttonCurrent and the buttonPrevious are not similar and that is where the switch takes place. Had been struggling with it for 2 days lol
I am looking to incorporate in my project using arduino with 5 buttons to pulse the associated relay That means that each switch will create a short single output pulse no matter how long the button is pressed Your help will be greatly appreciated Many thanks Erik Hoffman London, UK
Am I right that everytime you runs this code you have to make sure switch is off (int buttonPrevious = Low)? If you turn Arduino on and keep switch to on state then buttonCurrent and buttonPrevious will be both LOW so nothing will really happen, right?
What problems do you mean? perhaps you need to add edge detection to counter that your button registers a second click: th-cam.com/video/_56O7Gh6EbY/w-d-xo.html
Use an if statement and check whether your first button has been pressed or not, if it has then you can check for the second button, I hope this is what you asked for?
@@asali-channel i use the if statement of the 1st button then inside of the first button another if state and else if for the 2 button option (yes/no) but i dont know how to toggle the first button because i need to press it once (HIGH) then the option 2 buttons, not press it (high then low).
@@paoloacero7732 Oh I see what you mean, I made a video on this topic, what you are looking for is the first button to be "toggled" and aslong as the button hasn't been pressed again it has to stay "HIGH" here you go: th-cam.com/video/XQzQFwpnhRo/w-d-xo.html
,thanks asali for your tutorial. It's really good. I did it on my Arduino Uno. Keep a good work. Im waiting for your next tutorial. Mr. Asali can I suggest a video tutorial for timer countdown in a minute and increment time if push the button. thanks a lot.
it happens to be easier by counting and analizing pair amount of times pressed: val=digitalRead(bot); if(val==HIGH){ cont=cont+1; Serial.println("BOT UP"); if(cont%2==0){ analogWrite(led,LOW); }else{ analogWrite(led,HIGH); } delay(1000); }
That's an interesting question, I doubt it's possible in Arduino. Did you try to scroll through the Arduino forum itself already? forum.arduino.cc/index.php?topic=37130.0
thank you , please how can i add a multiplexer like cd4051 or 4067 ?
bro thank u so much I was stuck on this problem for hours
I wrote a shorter and clear way by watching this video, thanks a lot btw:
if(btnState && !btnStatePrev) ledState = !ledState;
digitalWrite(led, ledState);
btnStatePrev = btnState;
didnt know u can use the ! operator like this ty
For some reason I have to hold the button in order to make led bright up. really confuse on my own thing.
I searched the whole internet for a working code but continuously have the same problem as you, i hate my life
Where is the video when you say next week?
Toggling a pin can be reduced to one line of code:
digitalWrite(pin, !digitalRead(pin));
And there's no need to keep track of the previous state because an internal register in the processor is already doing that.
Can you please explain it briefly
but then it doesnt toggle it if your using a button because if you dont instantly press the button its going to start running it over and over so nothing really happens
Thanks you helped me crack the code! I learned that there is one cycle of the loop where the buttonCurrent and the buttonPrevious are not similar and that is where the switch takes place. Had been struggling with it for 2 days lol
Hey nsw?
I am looking to incorporate in my project using arduino with 5 buttons to pulse the associated relay
That means that each switch will create a short single output pulse no matter how long the button is pressed
Your help will be greatly appreciated
Many thanks
Erik Hoffman
London, UK
I find it complicated
Am I right that everytime you runs this code you have to make sure switch is off (int buttonPrevious = Low)? If you turn Arduino on and keep switch to on state then buttonCurrent and buttonPrevious will be both LOW so nothing will really happen, right?
how can i set for multiple buttons
What if you want it latch or stay on state unless if its yrigger again to turn off?
I'm having troubles controlling a servo this way. Can you help me out?
What problems do you mean? perhaps you need to add edge detection to counter that your button registers a second click: th-cam.com/video/_56O7Gh6EbY/w-d-xo.html
Thank you! I will try this now!
How would you do this but with a specified PWM value?
hello sir how to code if you want to add 2 button option after that toggeled first button sir hope you would help me.
Use an if statement and check whether your first button has been pressed or not, if it has then you can check for the second button, I hope this is what you asked for?
@@asali-channel i use the if statement of the 1st button then inside of the first button another if state and else if for the 2 button option (yes/no) but i dont know how to toggle the first button because i need to press it once (HIGH) then the option 2 buttons, not press it (high then low).
@@paoloacero7732 Oh I see what you mean, I made a video on this topic, what you are looking for is the first button to be "toggled" and aslong as the button hasn't been pressed again it has to stay "HIGH" here you go:
th-cam.com/video/XQzQFwpnhRo/w-d-xo.html
@@asali-channel you just paste this video link, btw great tutorial!
Instead of putting an if statement inside of an if statement, couldn't you just have two ands?
why does my led light light up but the button have no use?can anyone help?
I have the same problem...the LED lights up but the button doesnt work....
,thanks asali for your tutorial. It's really good. I did it on my Arduino Uno. Keep a good work. Im waiting for your next tutorial. Mr. Asali can I suggest a video tutorial for timer countdown in a minute and increment time if push the button. thanks a lot.
it happens to be easier by counting and analizing pair amount of times pressed:
val=digitalRead(bot);
if(val==HIGH){
cont=cont+1;
Serial.println("BOT UP");
if(cont%2==0){
analogWrite(led,LOW);
}else{
analogWrite(led,HIGH);
}
delay(1000);
}
can you do this in assembly language
That's an interesting question, I doubt it's possible in Arduino. Did you try to scroll through the Arduino forum itself already? forum.arduino.cc/index.php?topic=37130.0
why would u use assembly?
Thank u
Thank you this is for me a perfect example for beginners like me
bullshit
You watch simon senek
You have a good eye!
simple but powerful
Didn't work at all. People actually like coding? This shit is nightmarish.
hey can u freakin explai n properly especially the void loop thank you'
please improve your accent.
Hahaha I'll do my best
accent is nothing wrong tho
@@hongkitchong71 thanks buddy