Basic? LED problems!

Hello everybody!

I'm building a midi controller which has some LED's involved to show me what's happening. I'm using a nano and this is my first ever coding project. It's using 4 LED's and 4 buttons.

For the life of me I can't work out how to do the following;

  • Turn on a flashing LED with one button and then turn it off with another
  • have a button switch on an led for one second (without using delay)

I have been looking at this for hours and thought it was just best to ask one of you great people for ideas!

Thank you in advance!

There are plenty of tutorials online about that sort of thing. I don't think it should need to be rewritten here just special for you.

Post what you've got or what you've tried and we can help you find the issue. But I don't think you should expect anyone to write you a whole tutorial on how to do that when it's already out there in so many places.

Hi,
Where did I say I wanted someone to write out the entire code for me? I asked for ideas on how to find what I'm looking for. I just want to be pointed in the right direction. I can find plenty of posts of the 'blink' and 'blink without delay' codes for example and plenty of codes to turn an LED on and off but I've literally tried looking everywhere and I can't seem to find any guide on how to combine the two.

All I seem to find whenever anyone asks a question anywhere is 'look at the blink tutorial'

As mentioned:

Post what you've got or what you've tried and we can help you find the issue.

LCOLLINS1989:
Where did I say I wanted someone to write out the entire code for me?

Is that what he asked?

But I don't think you should expect anyone to write you a whole tutorial on how to do that when it's already out there in so many places.

No. "whole tutorial" is NOT "entire code"

I just want to be pointed in the right direction. I can find plenty of posts of the 'blink' and 'blink without delay' codes for example and plenty of codes to turn an LED on and off but I've literally tried looking everywhere and I can't seem to find any guide on how to combine the two.

BlinkWithoutDelay turns the led on and off. It's called "blinking a led" and you can't find on and off combined with blink?

And boy howdy ain't that global warming a hoax just like the moon landings, evilution and "millions of years", right?

LCOLLINS1989:
Hi,
Where did I say I wanted someone to write out the entire code for me?

You should maybe read that a little more carefully. I never said anything about writing code. Get the chip off your shoulder and give us something to work with here. Right now you're just bitching about your own inability to locate tutorials. That's not any of my fault.

  • Turn on a flashing LED with one button and then turn it off with another

Do you know how to use digitalRead to get the state of your button? If not, there are examples that came with the IDE that show you how. DO you know how to write an if statement to do something based on the state you get? If not then go do some basic C++ tutorials. Do you know how to use digitalWrite to turn the led on or off? If not see the Blink example. What more do you need?

You're asking for stuff that is literally lesson 1 in most tutorials. Don't try to tell me it's not out there. There may not be an example that does exactly what you want, but the pieces of it are certainly all over the place. Go learn enough to at least try and then post what you try here if it doesn't work and we will help you make it work.

Shame, I used to post my button and led examples left and right but my drive got wiped and I only went and found certain ones since.

I do have a button library that as of yesterday is faster and more solid than ever...... I could throw a blinky task to the example .ino and connect it to the status returned from the button object.

Once you have an understanding of BWD (aka non-blocking event-driven code), the rest is easier but button debouncing is a subject in itself.

Hi,
Welcome to the forum.

If you have got Blink Without Delay example working then you are halfway there.

In psuedocode, not valid C++ but a basic talk through the code outline

button1 starts flashing
button2 stops flashing
flash = Low

code;
if button1 pressed (changes from low to high or high to low, depending on how you wire your button)
{ flash = High}
if button2 pressed (changes from low to high or high to low, depending on how you wire your button)
{ flash = Low}
if flash == HIGH
{Blink Without Delay}

Hope this helps, it is very basic and may have some bugs.
You are looking for a change of state of your button, then set a variable "flash" to set the status of the flashing.

Tom.... :slight_smile:

Tom, those buttons need a cap across the leads, ie debounced once the code is free to run fast.

Hi,
I don't at this point see a need for debounce.
Each button only has one function.

Once the button has made contact, no matter how many bounces while pressed the flag has been set or reset.
Bouncing irrelevant.

Tom... :slight_smile:

So the button gets pressed and 6 press and release cycles get read, no problem just don't read the button for 50ms and assume it's all right you won't miss a thing?

They're two separate buttons. Pressing it once or six times does the same thing. It just turns the LED on.

And nobody can see the too-fast-to-see blinks that the press-release cycles will make.

Good for this, wait for the thread when it does make a difference and the OP has a solid belief that bounce doesn't matter for about 10 pages.

There wouldn't be any blinks smoke. Turning it off is a separate button. Pressing the on button is not going to make the off button bounce. The way this is written you press the on button and it turns the led on. You press it again and nothing happens.

I missed or forgot that part. It is good in a way for this purpose and it does simplify the project.

Putting a 1uF cap across the button leads or using debounce code are lessons for later then.

Putting a 1uF cap across the button leads or using debounce code are lessons for later then.

As long as us old guys can remember those lessons.

That's why we gotta pass them on!