How to replace Multiple Delays in a row with millis()

I tried your Wokwi... and the behaviour of the LEDs looked familiar... I think I 'tried' to help @stspringer with a very similar behaviour before... No idea if my submitted code was helpful to him but it was this: sketch.ino - Wokwi Arduino and ESP32 Simulator

Seems to behave in a similar manner.

The code or the OP? :wink:

SMH

a7

1 Like

Hello,
Button 5 double-click is the problem if you double click it enough times in [bumpForum.ino - Wokwi Arduino and ESP32 Simulator ](bumpForum.ino - Wokwi Arduino and ESP32 Simulator) it will eventually blink leds 6&7 and 8&9 and turn off 6 & 7 and 8 & 9 for a short time alternating between led 6 & 7 and 8 & 9 as it should other times it fails, it is not consistent. It seems to work after the 3rd double click, sometimes more double-clicks.

Button 5 is acting as it does in my script sometimes on a double click the LEDs blink properly back and forth and turn off and on, and sometimes led 6 & 7 stay on and never turn off, that is my issue. If you keep double-clicking on button 5 sometimes all is good and sometimes it never has led 6 & 7 turn off.

Button 4 - Works, you have to keep it pressed down for it to do it's job.

a physical "momentary-on" switch, is used for "one purpose" to blink the fog lights, either the low beams fog lights or both the low beams fog lights and the high beam fog lights, if the high beam fog lights are on.

Button 5 - Is also a physical "momentary-on" switch, but acts like "latched switch in code" this switch has 3 jobs

1: short press - turn on and keep on the high beam fog lights, short press again turns off the high beam fog lights

2: a double-click will turn on the police lights event with blinking led police sequence, another double-click will turn off the police lights sequence, and turn on the low beam fog lights only.

  1. Long press 2.5 seconds will turn off all the fog lights, another log press 2.5 seconds will turn on just the low beam fog lights.

I've had a skim over all the traffic your issue has generated and I think our help is actually hurting you.

You should look over all the threads, all the posts and start taking some of the very good advices offered.

There is no instant gratification to be found in this hobby.

There is a limit to how far you will get just hacking w/o knowing what you re (really) doing.

Go all the way back to learning same basic programming… because

there is limit to how much help you can get here, which limit you may have reached.

We all started somewhere. Slow your roll and settle in for a longish haul. You can see that your basic problem can b a crisp program of many fewer lines of code. Even if that example only did half your requirement, doulbing it would still come nowhere near 500+ lines.

A graphical representation of what you are trying to do would be tons better than the word salad you are serving up again and again. I see it has been suggested more than once.

a7

I can not test this so let me know if it works.

void setup( ) {
    pinMode( 6, OUTPUT ); // RED
    pinMode( 7, OUTPUT ); // BLUE
    pinMode( 8, OUTPUT ); // RED
    pinMode( 9, OUTPUT ); // BLUE
}

void flash( int pin1, int pin2) {
    bool drive = 1;

    for( int i = 6; i; i--  ) {
        digitalWrite( pin1, drive );
        digitalWrite( pin2, drive );
        delay( 50 );
        drive ^= 1;     // not tested but I think it will work
    }
}

void loop( ) {
    flash( 6, 7 );
    delay( 100 );
    flash( 8, 9 );
    delay( 100 );       // not in the original
}

Hello alto777,
Here is a youtube link to how the LEDs should blink when the double-click works in the simulator, sometimes they don't blink correctly.

Here is a link to it NOT working

I really appreciate your help, I know my code could be smaller and tighter, and more professional looking but as for now here are my thoughts on coding as a hobby in Arduino code.

"There is a limit to how far you will get just hacking w/o knowing what you're (really) doing."
I don't think you can call plugging in code from someone else's code hacking. I used to program in Visual Basic 6 professional, way back, and I remember I had to pull customers email addresses out of a work order.

Well, that is not an easy task "you have to eliminate any characters that an email address can't use", try it. So instead of reinventing the wheel I found some code on the web, altered it a little for my program and it worked fine. If you look at the code to extract an email address from a text file it is very intimidating, sort of like algorithms for time and calendar calculations. I can look at the code I found, and understand in general what is happening, but may not understand every line of the code, but if it works, why reinvent the wheel?

So in my case with this double-click firing off code from another script, that I found, the only issue is the fact that with a double-click on button 5, 2 of my 4 LEDs 6 & 7don't turn off completely, and then turn back on, in the blink sequence like the other 2 LED's *8 & 9 do. I don't think that is a "word salad" as you mentioned. You can see it NOT working in the bumpForum.ino - Wokwi Arduino and ESP32 Simulator

I know my issue has to be hunted down in the script I posted, but I figured someone with more experience may be able to see the problem faster than I could.

By the way, I found another script that uses an array with a sequencer and for loops to blink LED's like police lights, I had to add code to it, edit it, and alter it, for my script, and I got it to work in my script, and it works with my button 5 double-click 100%.

I do not understand all the code in this new script I found but it works. I can study it and grasp it better when I have more time, again why reinvent the wheel if this script works.

Even though I solved my problem with this new script I found, I still would like to know what is happening in the script I posted here, as a learning experience.

I didn't want to add confusion and post the new script I have here but here is the link to the script I found and it works in my script perfectly with the button 5 double-click Fun with Arduino 22 Flashlights with a Step Sequencer, array[], for() loop Fun with Arduino 22 Flashlights with a Step Sequencer, array[], for() loop – Fun with Arduino

If you like I can post my new script that works with the original double-click call commented out. Let me know if you want to see it.

Thank you again for your help, and I hope you and the others who are helping in this issue, will still continue to try to find the issue with my script, which may be an easy fix, or not.

tl;dr: I am thrilled that you have a working program to deploy.

I never saw the behaviour on your first video, ever. It's is not clear if you meant to say that something you posted previously behaved that way. I only saw the odd dimming of the ever-on right hand pair of LEDs at the flashing rate.

I may be at the extreme edge of a kind of brain dominance or simply by experience am the type who can absorb and understand a specification if it is presented graphically, hence my annoying requests for any kind of diagram. Although it is certainly possible to describe in words both tersely and unambiguously, the majority of word-orientated specs seem to omit, confuse or mistake certain subtleties. A combination of both is the norm for the heavies. Kinda like writing the $42.00 and "Forty Two Dollars & 00/100" on a check.

As for getting to the bottom of it (why it doesn't work, or works inconsistently), my doing would have to be at the expense of sleeping, going to the beach, getting after my taxes and... helping other people who want/need the kind of help I am prepared to offer.

I encourage you to do if it is that important! Or come back to it one day if you decide to learn more Arduino type programming and simply marvel.

Thank you for your general remarks. I tots understand where you are coming from and appreciate to where it is you want to go. You do you.

I must say, just in case we aren't talking amongst ourselves, that if you had kept all your inquiries in one thread you would probably have finished sooner.

I must also say that if from the start you had decided instead to get help writing a program that does the job and had put in the necessary work, you would probably have finished by now and ended up in a better place for the next project.

Or not.

TBC I can see how in context you may have considered "hacking" to be used in a perjorative sense. Not true! What you are doing is a part of what hacking consists in, and it is an entirely valid means of accomplishing things. There is no shame in hacking, I did not mean to imply otherwise.

There is a limit to how far you can get, how big a hack you can pull off, or how willing to help ppl who want everyone to become some kind of competent programmers might be.

CU

a7

Thank you Sir for your help and understanding. I am also glad I found a fix to my problem, with the script link I posted, with the array and sequencer and all. I will try and figure out my other script just for giggles when I have time to kill :slight_smile:

Must be nice going to the beach, I am in Buffalo Ny waiting for spring so I can ride my Harley LOL

Take care, and thanks again. By the way, you are super articulate, I am impressed.

Careful with that. You might end up refusing valid email address that have characters like + or * (which some Web sites annoyingly do). Most characters many people think are "invalid" in an email address actually are valid.

True

The local-part of the email address may use any of these ASCII characters:

  • uppercase and lowercase Latin letters A to Z and a to z;
  • digits 0 to 9;
  • special characters !#$%&'*+-/=?^_{|}~`;
  • dot ., provided that it is not the first or last character unless quoted, and provided also that it does not appear consecutively unless quoted (e.g. John..Doe@example.com is not allowed but "John..Doe"@example.com is allowed);
  • space and "(),:;<>@[\] characters are allowed with restrictions (they are only allowed inside a quoted string, as described in the paragraph below, and in addition, a backslash or double-quote must be preceded by a backslash);
  • comments are allowed with parentheses at either end of the local-part; e.g. john.smith(comment)@example.com and (comment)john.smith@example.com are both equivalent to john.smith@example.com.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.