Led should blink 3 times if button is pressed (HIGH) and then stop, but if button stays pressed (HIGH) for longer period of time, LED should still blink only 3 times and then stop until new press of a button. Now i made counter for a pushbutton that increments every time INPUT is high and is % by 2 so if 0 is left, then it should blink otherwise it stays low, but for some reason it doesn't work. Is my strategy wrong and there is other way to make what i want? Here is my code:
const int buttonPin = 3;
const int ledPin = 6;
int buttonPushCounter = 1;
int buttonState = 0;
int lastButtonState = 0;
anthonyHope:
Dont you just need to do the blink x3 every time the button becomes pressed. Atm its only going every 2nd time.
Mind you Im reading un- code-tagged code on my mobile which is a bit messy.
Yes it should blink every time button is pressed, it should be %1 instead of 2. Anyway it blinks 3 times when button is HIGH but it blinks 3 times again when button becomes LOW. Why is that
Please read the first post in any forum entitled how to use this forum. http://forum.arduino.cc/index.php/topic,148850.0.html .
Then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
If you are pulling the input HIGH, do you have a 10K pulldown resistor between the input and gnd?
Hi,
Try this code, I have changed to a bool value for the flash.
Also added Serial.print for debugging.
Set the IDE monitor to 115200 baud.
Make sure you have a pulldown resistor I mentioned in post #3.
TomGeorge:
Hi,
Try this code, I have changed to a bool value for the flash.
Also added Serial.print for debugging.
Set the IDE monitor to 115200 baud.
Make sure you have a pulldown resistor I mentioned in post #3.
const int buttonPin = 3;
const int ledPin = 6;
int buttonPushCounter = 1;
int buttonState = 0;
int lastButtonState = 0;
bool flashState = false;
Oh Thank you so much Tom. It works! I'll study this code and understand it completely now. People like you are really motivation for me. Thank you again and to all others.