Arduino Question I need an arduino code that does the follow

Arduino Question: I need an arduino code that does the following: When a push button switched is released, a timer is started (millis function). A hall sensor simulataneously notes each time a spinning object with a magnet on it passes by and prints out these times. Each time it does pass by, the time elapsed (from when the button was released) is recorded. If the object does not pass by for ten seconds, \"DONE\" is printed to the window as is the last time elapsed that was recorded. Thank You

PLEASE DO NOT COPY PASTE RANDOM CODE FROM GOOGLE

Solution

Ans: We assume that the millis() function is one of the most powerful functions of the Arduino library. This function returns the number of millisecond the current sketch has been running since the last reset. At first you might be thinking, well thats not every useful but consider how you tell time during the day. Effectively you look how many minutes have elapsed since midnight. Thats the idea behind mills().

now , we are going to explain in te form of program:

Basic Delay:

you are probably already familiar with this first code example. The Ardlino lde include this example as

void setup() {

pinmode(13, output);

}

void loop() {

digital write (13, HIGH); // set tge lED ON

delay (1000); // wait for a second

digital write (13, low); // set the LED off

delay (1000); // wait for a second

Reading each line of loop() in sequence the sketch:

1) Turns on pin 13\'s LED,

2) waits second ( or 1000 milliseconds)

3) Turns off pin 13\'s LED and,

4) wait second.

5) Then the entire sequence repeats.

for our 2nd example we are only going to delay for lms, but do so inside of a for() loop

void setup() {

pinmode (13, output);

}

void loop() {

digital write (13, HIGH); // set the LED on

for (int x=0; x<1000; x++) { // wait for second

delay(1);

}

digital write (13, Low); // set the LED on

for (int x=0) x<1000; x++) {

delay(1);

}}

In this example we added a second LED on pin 12 now lets sec how we could write the code.

void setup() {

pin mode (13, output);

pin mose (12 output);

}

void loop() {

digital write (13, HIGH); // set the LED on

for (int x=0); x<1000; x++) { // wait for a second

delay(1);

if (x==500) {

digital write (12, HIGH);

}}

digital write (13, low) // set the LED off

for (int x=0; x<1000; x++) { // wait for a second

delay(1);

if (x==500) {

digital write (12, Low);

starting with the first for() loop, while pin 13 is high, pin 12 will turn after 500 times through the for() loop.

The if () statement and digital write () function all take time, adding to the delay()

Arduino Question: I need an arduino code that does the following: When a push button switched is released, a timer is started (millis function). A hall sensor s
Arduino Question: I need an arduino code that does the following: When a push button switched is released, a timer is started (millis function). A hall sensor s

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site