Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1) There are two functions that must be included in every Arduino program list t

ID: 2293267 • Letter: 1

Question



1) There are two functions that must be included in every Arduino program list them and explain what they do. 2) Describe what the pinMode function is used for 3) Write some code (at most five lines) that will: a) configure pin 5 as a digital input and pin 13 as a digital output; b) read a value from pin 5; and c) write the value from pin 5 to pin 13 4) Write some code (at most five lines) that will: a) configure pin 9 as a PWM output; b) read a value from pin A0; c) write the value from pin A0 to pin 9 a. Hint: The values from the analogRead function are from 0 to 1023 while the analogWrite command only accepts values from 0 to 255. You'll need to adjust the value before writing it to pin 9! 5) Calculate the value of R1 in the following circuit (Vc 5 volts; forward voltage drop of diode = 2 volts; recommended current = 20 milliamps) LED1 R1 GND 6) In a few sentences, describe clearly the principle behind how software-based button debouncing is achieved in Listing 2-5 of the textbook.

Explanation / Answer

1. setup () and loop() are the essential functions in any arduino program. Both the fuctions have void return type.

The setup() function contains the settings like I/O's description and direction and it gets executed only once whenever arduino gets reset, restarted or a new sketch gets uploaded.

The loop() function contains the main code that defines its functionality.This function runs continuously unless reset, restart or new sketch gets uploaded.

2. pinMode function is used to configure arduino pins as an INPUT or OUTPUT or INPUT_PULLUP

3.

int val=0;

void setup()

{

pinMode(5, INPUT);

pinMode(13, OUTPUT);

}

void loop()

{

val = digitalRead(5);

digitalWrite(13, val);

}

4.

int val=0;

void setup()

{

pinMode(A0, INPUT);

pinMode(9, OUTPUT);

}

void loop()

{

val = analogRead(A0);

analogWrite(9, (val/4));

}

5. Applying KVL

VCC - VLED1 - IR1 = 0

R1 = (5 - 2) / 20mA = 150 ohm