Solve Part 2 Documentl Word ences Mailings Review View Foxit Reader PDF Tell me
ID: 3878000 • Letter: S
Question
Solve Part 2 Documentl Word ences Mailings Review View Foxit Reader PDF Tell me ·A-1 l 1 Normal 11 No Spac. Heading 1 Heading 2 Paragraph Style PRE-LAB SECTION Part 2: Arduino C Programming Research how to use a built-in function called dclax0, and give a code example of using the function using the function Explain the difference between using these two functions, and when to use each of Research how to use a built-in fiaction called millisO. and give a code example of . these functions Part 3: Hall Sensor (AH Q-PG-A) The datashet for AHIS0 A is available on CaGo over the document, and find out the following quantities The recommen oebent temperature in C 40 C to 85'C operating t erat . The recommended range voltage . The maximum outoltage when . The maxm utput current when the snit 25V to 5.5V operating witch is on onat room temperature The mum output current when the switch is ofcom temperature DOLLExplanation / Answer
delay() - The delay function suspends execution for a given number of milliseconds(passed as argument). The argument passed in the delay function is an unsigned integer. To make a delay of 1 sec, one must pass 1000 in the delay function (1 sec = 1000 milliseconds)
int state=HIGH; // Sets initial state of LED ON
const int pin=13 // led pin number
unsigned int wait = 11000; // delays set to 11000 milliseconds
void setup(){
pinMode(pin,OUTPUT); // sets the digital pin as output
}
void loop()
{ state = !state; // toggles the state (on to off, off to on)
digitalWrite(pin, state); // Sets LED OFF
delay(wait); // terminated the execution for 11000 milliseconds(wait = 11000)
state = !state; // toggles the state (on to off, off to on)
digitalWrite(pin, state); // Sets LED ON
delay(wait); // terminated the execution for 11000 milliseconds(wait = 11000)
}
millis() - The millis function does not terminate the execution, instead it schedules the time to act again and keeps an eye on the clock to start acting when the time is right. Also, the processor is kept free for other instructions.
int state=HIGH; // Sets initial state of LED ON
const int pin=13 // led pin number
unsigned int wait = 11000; // delays set to 11000 milliseconds
unsigned long preTime = 0; // sets previous milliseconds as 0
void setup(){
pinMode(pin,OUTPUT); // sets the digital pin as output
digitalWrite(pin, LOW); // Sets LED OFF
}
void loop(){
unsigned long currTime = millis(); // saves the current milliseconds in currTime
/* IF condition to check if wait time has passed */
if (currTime - preTime >= wait){
state = !state; // flips the state
digitalWrite(pin, state); // sets LED with New state
preTime = millis(); // save the current time as previous time
}
}
Difference Between delay() and millis()
the delay function terminates the execution for the given time while the millis keep the processor free for other instructions it schedules the time to act again and keeps an eye on the clock to start acting when the time is right.
Shortly, delay will pause the code while millis will allow to continue on the subsequent instructions.
One must use millis() instead of delay() when he plans to do more than one things at once as it does not terminate the program. If you are just flashing only one LED you can use delay.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.