Hello! I am a super noob here! I am working on writing a code that turns on a LED with the press of a button. Then the LED will blink for some amount of time. Finally, when you press the button again it turns off. I have got the LED to turn on and blink and then let me turn it off. However, the trouble I am having is that if I want to turn the button on again and get it to blink I have to reset my ArduinoNano. (i.e. There is only one run per reset.) I want my code to run to where I am able to have it blink and then turn it off as many times as I would like. Can someone please help me? I am new to the Arduino language. Some example code or code to look at would be helpful thank you! I will attach my code!
1. You have said that you are supper noob; if so, from where have you got the codes that you have attached?
2. I tried to read your codes, but I failed as the presentation style is totally illiterate. There is something in programming called literate programming which means: If you wish that your codes are presented for others to read and comment, then maintain the alignment of the braces. For example:for(expression){statements;} is perfectly alright syntactically; but, it is illiterate when presented to others. The literate format:
for(expression)
{
//statements;
}
3. You are a noob, and I am a novice. I hope that I have understood your logic of playing with the led2 and button2. I assume that you have an external pull-up resistor connected with your button2. led2 is connected at digital pin-10, and button2 is connected with digital pin-9 with internal pull-up resistor enabled.
I have taken your programming problem as an exercise for me, and I am presenting my solution (tested) below with a hope that it might be helpful for you!
Okay, so I was able to download and upload your code to my ArduinoNano. It worked, but it doesn't quite do what I am needing it to do. Your code makes the led blink indefinitely and the button isn't incorporated. I need code that turns on the light and has it blink for some amount of time, then be able to shut off with another press of the button. Then when I press the button a third time it will start over and blink again and then turn off when the button is pressed a fourth time.
Did you think about reply #1? It will require thought. It isn't just a simple gimme da code. But your code isn't that far off and if you think about that one thing you'll be almost there.
By setting var = 0 at the end of my code. I was able to get it to go through its cycle of blinks! The only problem now is it won't turn off. How should I go about making it turn off and then go through the cycle of blinks again and then turn off and then turn off again with the cycle?