Question

How to start a variable to keep track of time that has passed in arduino I...

How to start a variable to keep track of time that has passed in arduino
I want a code on how to record how much time has passed and use it in an if statement

Arduino uses a form of C

0 0
Add a comment Improve this question Transcribed image text
Answer #1

ARDUINO CODE:

unsigned long start, seconds;
void setup()
{
    Serial.begin(9600); // Begin serial communication
    start = millis(); // Get starting time
}
void loop()
{
    // Get current time in milliseconds and convert it to seconds
    seconds = (millis() - start)/1000;
    // A short delay for better accuracy
    delay(100);
    // After 5 seconds, execute this if condition
    if(seconds > 5){
      Serial.print(seconds);
      Serial.println(" seconds elapsed");
      delay(1000);
    }
}

SERIAL OUTPUT:

FOR ANY HELP JUST DROP A COMMENT

Add a comment
Know the answer?
Add Answer to:
How to start a variable to keep track of time that has passed in arduino I...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • If a player rolls 2 dice, how do i keep track of the number of times...

    If a player rolls 2 dice, how do i keep track of the number of times a player rolls those 2 dice? Please code in C Please show example code

  • This question is about the Arduino code. Please complete a 4-input circuit on your Arduino. Your...

    This question is about the Arduino code. Please complete a 4-input circuit on your Arduino. Your circuit, in addition to cycling through a binary representation of the numbers 0-15 using LEDs, should use the Serial port to output the decimal equivalent of each of the numbers in the format: Output: 15 ... if the value was 1111, and so forth. You will be asked to upload your code as well as a photo of your working breadboard circuit. Add comments...

  • Use python to code! Q1 - You need to keep track of book titles. Write code...

    Use python to code! Q1 - You need to keep track of book titles. Write code using function(s) that will allow the user to do the following. 1. Add book titles to the list. 2. Delete book titles anywhere in the list by value. 3. Delete a book by position. Note: if you wish to display the booklist as a vertical number booklist , that is ok (that is also a hint) 4. Insert book titles anywhere in the list....

  • VEND CODE -> VEND NAME Perry Computer Inc. uses the following INVOICE table keep track of...

    VEND CODE -> VEND NAME Perry Computer Inc. uses the following INVOICE table keep track of their data. Relational schema is listed below. INVOICE (INV NUM, PROD NUM, SALE_DATE, PROD_DESCRIPTION, VEND_CODE, VEND_NAME, NUM SOLD, PROD_PRICE) Where: INV NUM -> SALE DATE PROD NUM-PROD DESCRIPTION, VEND_CODE, VEND NAME, PROD PRICE QUESTION: C. Propose a better design (with no data redundancy) and indicate the normal form of your table(s). Please use relational schema format like the INVOICE table in Perry's original design....

  • IN JAVA: Design a system for a bookstore that allows the owner to keep track of...

    IN JAVA: Design a system for a bookstore that allows the owner to keep track of the store’s inventory and members. The store sells three types of products: books, CDs, and DVDs. The store offers two types memberships to customers: regular memberships and premium memberships. The regular membership is free, while the premium members pay a fee every month. For this reason, the store keeps track of payment method and whether the fee is paid on time for the premium...

  • (help)Use this business description to make an ERD. A grocery store wants to keep track of...

    (help)Use this business description to make an ERD. A grocery store wants to keep track of its departments and employees.  For each department, the store wants to record a department ID, a name, and a location.  For each employee, the store wants to record an ID, a first name, a last name, a start date, and a phone number.  A department can have many employees. The store wants to be able to assign employees in more than one department. Part time employees can...

  • Rutherfordium-261 has a half life of 81 seconds. How much time has passed if 12.5 %...

    Rutherfordium-261 has a half life of 81 seconds. How much time has passed if 12.5 % of the original sample remains? 243 seconds 162 seconds 324 seconds 81 seconds

  • 2. Your lab requires you to keep track of the Radioactive Material: Each Month you must...

    2. Your lab requires you to keep track of the Radioactive Material: Each Month you must record what has been used and how much remains. No one has removed any of the isotopes. How much was there on Feb 1? on March 1? 31 days in January 28 days in February Isotope Half-life Jan 1 Feb 1 March 1 100μCi 31 32p 14.29 days 28 355 86.35 days 1mCi 31 100uci- HalFlife 1429Days

  • how can i extract specific value and strings variable in R CODE for example what if...

    how can i extract specific value and strings variable in R CODE for example what if i want to extract the study time of TDU STUDNETS students = c("TDU","CSD","FSD"," ASD") study time=c(13, 11.2, 5.4, 16.0)

  • I want to use a stepping motor to control the number of steps it moves. I set the “step revolution” to 60 and I set the...

    I want to use a stepping motor to control the number of steps it moves. I set the “step revolution” to 60 and I set the number of steps to 1. But it hasn’t stopped for a long time and has been walking. I am using a Arduino IDE to make a writing machine (X-Y Plotter) It would be better if you could give me the code and explain it.

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT