element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Arduino Forum When is the function delay() a delay?
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • Replies 41 replies
  • Subscribers 389 subscribers
  • Views 7361 views
  • Users 0 members are here
  • delay
  • arduino_code
Related

When is the function delay() a delay?

colporteur
colporteur over 2 years ago

else if (MainDepartureState == LOW && MainArrivalState == LOW) {
        if (startupMain == HIGH) {
          // pulse turnout for Main train
          digitalWrite(Main_Turnout, HIGH);
          relayDelay();//<-----1
          digitalWrite(Main_Turnout, LOW);
          if (deBug == HIGH) {
            Serial.println("The Main Turnout Activated");
          }
          // Engage Motor for Main
          motors.setSpeedB(minSpeedB);  // Start Motor for Main
          motors.forwardB();
          PowerMain = LOW;
          startupMain = LOW;
          delay(300000);//<----2
          if (deBug == HIGH) {
            Serial.println("Motor Delay Complete");
          }

According to what I have read “The delay() function allows you to pause the execution of your Arduino code for a specified period.”

Why are the delays I am using not working or the values are so extreme? How can I best accomplish a delay?

I tried using the delay() function at point <----1 in my code and it failed miserably. I wanted to activate a relay by turning it on, waiting for relay to engage (delay(2000), then turn it off. The delay(2000) two seconds didn’t work. I wrote a little relay routine that accomplish what I wanted but why did delay(2000) not give me two seconds?

I am using delay() function at <----2 in the code but the value doesn’t reflect the actual delay. I needed to generate some wait time for the motor to engage and trigger a sensor. My desire was a three second delay(3000) but the delay(300000) was a value that actually worked. That would be 300 seconds yes/no?

I'm a code resurrectionist and not an actual programmer. I will try and muddle through discussions 

  • Sign in to reply
  • Cancel

Top Replies

  • colporteur
    colporteur over 2 years ago +6
    Based on GL shared insight, I used a different set of PWM pins so as not to muck with the delay() timer. I also took the BE suggestions and used subtraction in the millis routines. I am happy to report…
  • Gough Lui
    Gough Lui over 2 years ago in reply to colporteur +5
    //user input variables int turnout_delay = 10000; //delay for relay contacts to engage int motor_delay = 900000; //delay for motor to move train unsigned long time_now = 0; int type cannot store outside…
  • Gough Lui
    Gough Lui over 2 years ago in reply to colporteur +3
    I think that it helps if one can see names like "TCCR0B" and know inside that it is short for "Timer Control Counter Register" then that should immediately set-off alarm bells in one's head. Gough Lui…
Parents
  • colporteur
    colporteur over 2 years ago

    Based on GL shared insight, I used a different set of PWM pins so as not to muck with the delay() timer. I also took the BE suggestions and used subtraction in the millis routines. I am happy to report control over delay() has been restored but am not using it now in favour of the millis routines.

    Much thanks to those folks that chimed in with offerings. Two thumbs up to the community!

    • Cancel
    • Vote Up +6 Vote Down
    • Sign in to reply
    • Cancel
Reply
  • colporteur
    colporteur over 2 years ago

    Based on GL shared insight, I used a different set of PWM pins so as not to muck with the delay() timer. I also took the BE suggestions and used subtraction in the millis routines. I am happy to report control over delay() has been restored but am not using it now in favour of the millis routines.

    Much thanks to those folks that chimed in with offerings. Two thumbs up to the community!

    • Cancel
    • Vote Up +6 Vote Down
    • Sign in to reply
    • Cancel
Children
No Data
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube