element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Members
    Members
    • Benefits of Membership
    • Achievement Levels
    • Members Area
    • Personal Blogs
    • Feedback and Support
    • What's New on element14
  • Learn
    Learn
    • Learning Center
    • eBooks
    • STEM Academy
    • Webinars, Training and Events
    • More
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • More
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • More
  • Products
    Products
    • Arduino
    • Dev Tools
    • Manufacturers
    • Raspberry Pi
    • RoadTests & Reviews
    • Avnet Boards Community
    • More
  • 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
Arduino
  • Products
  • More
Arduino
Arduino Forum arduino single signal digital
  • Blog
  • Forum
  • Documents
  • Events
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Arduino requires membership for participation - click to join
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Verified Answer
  • Replies 5 replies
  • Answers 2 answers
  • Subscribers 93 subscribers
  • Views 273 views
  • Users 0 members are here
Related

arduino single signal digital

balexfox
balexfox over 1 year ago

I ask for help I'm not good at Arduino
I need to send a single signal to the outputs only without delay. oscillogram attached time. signal for a certain time high then low then high again. thanks for the help. second signal high then low to the end. thank you

 

  • Reply
  • Cancel
  • Cancel

Top Replies

  • javagoza
    javagoza over 1 year ago +1 verified

    Can this help?

     

    #define SIGNAL1_PIN  5
    #define SIGNAL2_PIN  8
    #define SIGNAL1_PULSE_LENGTH_MS 2000
    #define SIGNAL2_START_DELAY_MS 500 
    
    void setup() {
    pinMode(SIGNAL1_PIN, OUTPUT);
    pinMode(SIGNAL2_PIN, OUTPUT…

  • balexfox
    balexfox over 1 year ago in reply to javagoza +1 suggested

    delay is not suitable because it slows down the code and I have a lot of it. Here's an example I don't know how to fix it.

     

    unsigned long currentMillis = millis();

    unsigned long currentMillis2 = millis…

  • balexfox
    balexfox over 1 year ago in reply to javagoza +1

    thank you very much

  • javagoza
    0 javagoza over 1 year ago

    Can this help?

     

    #define SIGNAL1_PIN  5
    #define SIGNAL2_PIN  8
    #define SIGNAL1_PULSE_LENGTH_MS 2000
    #define SIGNAL2_START_DELAY_MS 500 
    
    void setup() {
    pinMode(SIGNAL1_PIN, OUTPUT);
    pinMode(SIGNAL2_PIN, OUTPUT);
    digitalWrite(SIGNAL1_PIN, HIGH);
    digitalWrite(SIGNAL2_PIN, HIGH);
    }
    
    void pulseS1LowS2() {
    digitalWrite(SIGNAL1_PIN, LOW);
    delay(SIGNAL2_START_DELAY_MS);
    digitalWrite(SIGNAL2_PIN, LOW);
    delay(SIGNAL1_PULSE_LENGTH_MS - SIGNAL2_START_DELAY_MS);
    digitalWrite(SIGNAL1_PIN, HIGH);
    }
    
    void loop() {
      // call pulseS1LowS2() when needed
    }

    • Cancel
    • Up +1 Down
    • Reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • balexfox
    0 balexfox over 1 year ago in reply to javagoza

    delay is not suitable because it slows down the code and I have a lot of it. Here's an example I don't know how to fix it.

     

    unsigned long currentMillis = millis();

    unsigned long currentMillis2 = millis();

     

     

    // These variables store the flash pattern

    // and the current state of the LED

        

    int ledPin =  13;

    int ledPin2 =  12;// the number of the LED pin

    int ledState = LOW;

    int ledState2 = LOW; // ledState used to set the LED

    unsigned long previousMillis = 0;

    unsigned long previousMillis2 = 0;// will store last time LED was updated

    long OnTime = 100;

    long OnTime2 = 50;// milliseconds of on-time

    long OffTime = 7000;

    long OffTime2 = 5000;// milliseconds of off-time

     

     

        

    void setup()

    {

      // set the digital pin as output:

      pinMode(ledPin, OUTPUT);

      pinMode(ledPin2, OUTPUT);     

    }

        

    void loop()

    {

      // check to see if it's time to change the state of the LED

      unsigned long currentMillis = millis();

      unsigned long currentMillis2 = millis();

        

      if((ledState == LOW) && (currentMillis - previousMillis >= OnTime))

      {

        ledState = HIGH;  // Turn it off

        previousMillis = currentMillis;  // Remember the time

        digitalWrite(ledPin, ledState);  // Update the actual LED

      }

      else if ((ledState == HIGH) && (currentMillis - previousMillis >= OffTime))

      {

        ledState = HIGH;  // turn it on

        previousMillis = currentMillis;   // Remember the time

        digitalWrite(ledPin, ledState);    // Update the actual LED

      }

     

    // second signal

      if((ledState2 == LOW) && (currentMillis2 - previousMillis2 >= OnTime2))

      {

        ledState2 = HIGH;  // Turn it off

        previousMillis2 = currentMillis2;  // Remember the time

        digitalWrite(ledPin2, ledState2);  // Update the actual LED

      }

      else if ((ledState2 == HIGH) && (currentMillis2 - previousMillis2 >= OffTime2))

      {

        ledState2 = LOW;  // turn it on

        previousMillis2 = currentMillis2;   // Remember the time

        digitalWrite(ledPin2, ledState2);    // Update the actual LED

      }

     

    }

    • Cancel
    • Up +1 Down
    • Reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • balexfox
    0 balexfox over 1 year ago in reply to javagoza

    ok i will try

    • Cancel
    • Up 0 Down
    • Reply
    • Verify Answer
    • Cancel
  • balexfox
    0 balexfox over 1 year ago in reply to javagoza

    thank you very much

    • Cancel
    • Up +1 Down
    • Reply
    • Verify Answer
    • Cancel
  • javagoza
    0 javagoza over 1 year ago in reply to balexfox

    I'm glad you've solved!

     

    if later you need to do things while waiting to change state, then instead of using blocking delays you can use timers or any library for no-blocking delays:

     

    GitHub - contrem/arduino-timer: Non-blocking library for delaying function calls

    or

    How to code Timers and Delays in Arduino (forward.com.au)

    • Cancel
    • Up +1 Down
    • Reply
    • Verify Answer
    • Reject Answer
    • Cancel
Element14

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 © 2022 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

  • Facebook
  • Twitter
  • linkedin
  • YouTube