Question

In: Electrical Engineering

b. Copy the text below into your program. /* * Purpose: Read a 0V-5V value from...

b. Copy the text below into your program. /*

* Purpose: Read a 0V-5V value from analog pin A1

* and convert it to a 10-bit (0-1023) number. */

void setup() {

Serial.begin(115200); //set serial comm to 115 kbps }

void loop()

{ int pot_val; //input - potentiometer value

// analogRead() converts 0V-5V to 0-1023 pot_val = analogRead(1);

//read from Analog pin 1 Serial.println(pot_val); //print to serial monitor }

c. Add the function delay() from lab0 to make the readings 1x per second.

d. Write code to display formatted output on the serial monitor as shown below:

Voltage Integer Binary HEX

0.406 83 1010011 53

0.415 85 1010101 55 ...

(ii) Write a formula for converting an integer value (0 to 1023) to an analog voltage, where 0V corresponds to integer 0 and 5V corresponds to integer 1023.

Solutions

Expert Solution

b) The analogRead(pin) function reads the value from the specified analog pin. It returns a 10-bit integer that maps input voltages between 0 and 5 volts to 0 and 1023. More information about the function can be found here: https://www.arduino.cc/reference/en/language/functions/analog-io/analogread/

The original program is:

/*
* Purpose: Read a 0V-5V value from analog pin A1
* and convert it to a 10-bit (0-1023) number.
*/

void setup() {
Serial.begin(115200); // set serial comm to 115 kBaud
}

void loop() {

int pot_val; // input - potentiometer value

// analogRead() converts 0V-5V to 0-1023
pot_val = analogRead(1); // read from Analog pin 1

Serial.println(pot_val); // print to serial monitor
}

c) A delay can be realized by using the delay function. It accepts a single argument, the delay in miliseconds. The program with the added delay functionality:

/*
* Purpose: Read a 0V-5V value from analog pin A1
* and convert it to a 10-bit (0-1023) number.
*/

void setup() {
Serial.begin(115200); // set serial comm to 115 kBaud
}

void loop() {

int pot_val; // input - potentiometer value

// analogRead() converts 0V-5V to 0-1023
pot_val = analogRead(1); // read from Analog pin 1

Serial.println(pot_val); // print to serial monitor

delay(1000);
}

d) We can make use of the second argument of the Serial.print() function to specify the format of the output. More information about the function can be found here: https://www.arduino.cc/en/Serial/Print

/*
* Purpose: Read a 0V-5V value from analog pin A1
* and convert it to a 10-bit (0-1023) number.
*/

void setup() {
Serial.begin(115200); // set serial comm to 115 kBaud
Serial.println("Voltage Integer Binary HEX");
}

void loop() {

int pot_val; // input - potentiometer value

// analogRead() converts 0V-5V to 0-1023
pot_val = analogRead(1); // read from Analog pin 1

Serial.print(pot_val * 5.0 / 1023);
Serial.print("\t");

Serial.print(pot_val);
Serial.print("\t");

Serial.print(pot_val, BIN);
Serial.print("\t");

Serial.println(pot_val, HEX);

delay(1000);
}

(ii)

Please leave a positive rating if the answer is satisfactory or leave a comment if more explanation is needed.


Related Solutions

Write a complete C program that read the text below and save the text in a...
Write a complete C program that read the text below and save the text in a new file "second.txt" with the same text written in all uppercase. "Beedle the Bard was an English wizard and author of wizarding fairytales. Beedle was born in Yorkshire, England. At some point in his life he wrote The Tales of Beedle the Bard . The only known image of Beedle is a woodcut that shows him with a "luxuriant" beard. Beedle wrote in ancient...
Complete the program to read in values from a text file. The values will be the...
Complete the program to read in values from a text file. The values will be the scores on several assignments by the students in a class. Each row of values represents a specific student's scores. Each column represents the scores of all students on a specific assignment. So a specific value is a specific student's score on a specific assignment. The first two values in the text file will give the number of students (number of rows) and the number...
Please write a java program to write to a text file and to read from a...
Please write a java program to write to a text file and to read from a text file.
Read about the Perry Preschool Program in Ypsilanti, Michigan in your text and describe it to...
Read about the Perry Preschool Program in Ypsilanti, Michigan in your text and describe it to me using a good paragraph. List at least 4 good reasons to continue using the program. (5 pts.)
Design a program that will read each line of text from a file, print it out...
Design a program that will read each line of text from a file, print it out to the screen in forward and reverse order and determine if it is a palindrome, ignoring case, spaces, and punctuation. (A palindrome is a phrase that reads the same both forwards and backwards.) Example program run: A Toyota's a Toyota atoyoT a s'atoyoT A This is a palindrome! Hello World dlroW olleH This is NOT a palindrome! Note: You are only designing the program...
Below is an email that needs significant revision. Copy the text below into a Google Doc,...
Below is an email that needs significant revision. Copy the text below into a Google Doc, rewrite the entire email, and submit the link. Be sure to pay close attention to the subject line, clarity, structure, support, and voice. To: Department Managers From: Aaron Alexander <[email protected]> Subject:   Invitation to Help Interview Possible Interns Cc: Bcc:         You are invited to help us interview six excellent student candidates for three paid internships. These potential interns from our local state university...
i-Read about the Oregon parenting skills program (OSLC) in your text and describe it to me...
i-Read about the Oregon parenting skills program (OSLC) in your text and describe it to me using a good paragraph. List at least 3 good reasons to continue using the program. (4 pts.)
(C++) Write a program to read from a grade database (data.txt). The database (text file) has...
(C++) Write a program to read from a grade database (data.txt). The database (text file) has students names, and grades for 10 quizzes.Use the given function prototypes to write the functions. Have main call your functions. The arrays should be declared in main() and passed to the functions as parameters. This is an exercise in parallel arrays, int and char 2 dim arrays. Function prototypes: int readData(ifstream &iFile, int scores[][10], char names[][30]); This functions takes the file stream parameter inFile...
Python program: Write a program that reads a text file named test_scores.txt to read the name...
Python program: Write a program that reads a text file named test_scores.txt to read the name of the student and his/her scores for 3 tests. The program should display class average for first test (average of scores of test 1) and average (average of 3 tests) for each student. Expected Output: ['John', '25', '26', '27'] ['Michael', '24', '28', '29'] ['Adelle', '23', '24', '20'] [['John', '25', '26', '27'], ['Michael', '24', '28', '29'], ['Adelle', '23', '24', '20']] Class average for test 1...
Please read the article below (copy into your address bar, in case you dont undersatnd how...
Please read the article below (copy into your address bar, in case you dont undersatnd how internet works): https://physicsinfootballgrade11bcss.weebly.com/energy-work-power.html And provide a 250 word summary of the article and how it applies to the concepts of kinetic energy, work, and power. Also provide a description of how to figure kinetic energy, work, and power. If you can provide an additional resource. THIS HAS TO CONTAIN A SUMMARY OF THE ARTICLE AND BE RELATED TO THE ARTICLE OR I WILL NOT...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT